Flutter安装后Dart版本显示1.24.3而非2.x的问题求助
Hey there! I’ve run into this exact issue before—let’s break down what’s happening and how to fix it.
Why the Version Mismatch?
The problem boils down to two separate Dart installations on your system:
- An old standalone Dart SDK located at
/usr/local/bin/dart—this is the one your terminal is currently picking up - The Flutter-bundled Dart SDK that came with your Flutter upgrade (the 2.x version you see in
flutter --version)
When you run dart --version, your shell uses the first dart executable it finds in your PATH environment variable. Right now, /usr/local/bin is listed before Flutter’s bin directory, so it’s grabbing the outdated version instead of Flutter’s newer one.
How to Fix It
Follow these steps to prioritize Flutter’s Dart SDK:
Open your shell configuration file
- For Zsh (default on newer macOS), edit
~/.zshrc - For Bash, edit
~/.bash_profileor~/.bashrc
- For Zsh (default on newer macOS), edit
Adjust your
PATHorder
Look for lines that set yourPATH. Make sure the path to your Flutterbindirectory comes before/usr/local/bin. For example, if Flutter is installed in your home folder:# Put Flutter's bin directory first export PATH="$HOME/flutter/bin:$PATH" # Then other system paths like /usr/local/bin export PATH="/usr/local/bin:$PATH"Refresh your shell environment
Run this command to apply the changes immediately (replace with your config file if needed):source ~/.zshrcVerify the fix
- Run
where dartagain—you should see Flutter’s Dart path listed first - Run
dart --version; it should now match the Dart version shown influtter --version
- Run
Alternative Option (If You Don’t Need Standalone Dart)
If you don’t use the standalone Dart SDK for any other projects, you can simply delete the old executable:
rm /usr/local/bin/dart
This will force your shell to use Flutter’s bundled Dart by default.
内容的提问来源于stack exchange,提问作者Chris G.

