Flutter keeps retrying 'pub upgrade' for its own tool
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds...Short answer
The flutter command rebuilds its own tool and downloads packages from pub.dev to do it. The retry loop means that download fails. Check proxy variables, a mirror set by PUB_HOSTED_URL, and security software blocking dart, then confirm pub.dev is reachable.
Fix it fast
1Find out which cause you have
Check whether this machine can reach pub.dev at all, and whether any pub environment variable is set.
curl -I https://pub.dev env | grep -i "pub_hosted_url\|https_proxy\|http_proxy"2Match what you see, then jump to its fix
- 1
curl works in a browser or VPN session but fails in the terminal, and no https_proxy is setA proxy is needed but pub does not know about itFix - 2
The log mentions a socket error while finding a package at pub.devA firewall or security program blocks dartFix - 3
env shows PUB_HOSTED_URL, often left from an earlier setupPUB_HOSTED_URL points to a mirror that is down or wrongFix
- 1
What does the error look like?
Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds...Got socket error trying to find package
Cause 1 of 3
A proxy is needed but pub does not know about it
1Check
From the command line, pub honors the http_proxy and https_proxy environment variables, so a terminal behind a corporate proxy needs them.
echo "$https_proxy"2Fix
Set the variable for your shell, with credentials if the proxy needs them.
export https_proxy=hostname:port
# with credentials:
export https_proxy=username:password@hostname:port3Verify
Run Flutter again.
flutter --versionConfirmed by dart.dev
Cause 2 of 3
A firewall or security program blocks dart
1Check
Pub's own troubleshooting says to check the connection and to confirm no firewall or security software blocks the dart process.
curl -I https://pub.dev2Fix
Allow the dart executable, and allow pub.dev in your security product. Some products need pub.dev and pub.dartlang.org added to a trusted zone.
# no command: change the setting in your firewall or security product3Verify
Run Flutter again.
flutter --versionConfirmed by dart.dev
Cause 3 of 3
PUB_HOSTED_URL points to a mirror that is down or wrong
1Check
Pub downloads from pub.dev unless PUB_HOSTED_URL names another server.
echo "$PUB_HOSTED_URL"2Fix
Unset it, or set it to a mirror that currently works.
unset PUB_HOSTED_URL
# or point it at a mirror you trust:
export PUB_HOSTED_URL=https://pub.example.com3Verify
Run Flutter again.
flutter --versionConfirmed by dart.dev
How do I stop it coming back?
- Keep proxy and mirror variables in one shell profile, so you know where to look.
- Check pub.dev reachability first when any Flutter command hangs on a download.
- Remove temporary mirror settings when you leave the network that needed them.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- Qist BazaarA buy-now-pay-later marketplace built from a blank repo, now past 100K downloads on Google Play.
- SessionBirdAn omnichannel engagement suite in Flutter: campaigns, chatbot, tickets, analytics and live calling.
Related fixes
Mobile apps
Terminal says pub: command not found after installing Dart
dart: command not found
The standalone pub program no longer exists in current Dart.
2 causes, each with a fixMobile apps
The terminal cannot find the flutter or dart command
zsh: command not found: flutter
The flutter and dart programs both live in the bin folder of the Flutter SDK, so one PATH entry gives you both.
3 causes, each with a fixMobile apps
flutter doctor warns that dart on your path is not in the Flutter SDK
Consider adding C:\flutter\bin to the front of your path.
flutter doctor found a dart program on your PATH that lives outside the Flutter SDK folder, usually a separate Dart SDK installed earlier in the list.
3 causes, each with a fixMobile apps
flutter doctor fails the Network resources check
A cryptographic error occurred while checking
The Network resources check sends a request to a fixed list of hosts and fails if one does not answer.
2 causes, each with a fixMobile apps
A Flutter command says it cannot find pubspec.yaml
This command should be run from the root of your Flutter project.
Flutter and Dart read pubspec.yaml from the current working directory.
3 causes, each with a fixMobile apps
Terminal says fvm: command not found after installing FVM
zsh: command not found: fvm
The shell cannot find an fvm executable.
2 causes, each with a fix