系统环境:MacOS 13,M1芯片
1. 安装HomeBrew:
/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)" speed
2. 使用brew安装Fvm:
brew tap leoafarias/fvm
brew install fvm
3.配置FVM_HOME:
export FVM_HOME="$HOME/fvm"
4. 安装flutter SDK
查看远程flutter 发布的SDK
fvm releases
报错信息:
Failed to retrieve the Flutter SDK from: https://flutter-io.cn/flutter_infra_release/releases/releases_macos.json
Fvm will use the value set on env FLUTTER_STORAGE_BASE_URL to check versions
if you are located in China, please see this page: https://flutter.dev/community/china
Please run command with --verbose if you want more information
执行:查看下报错详情
fvm releases --verbose
报错详情:
[ 0.001s] SocketException: Connection refused (OS Error: Connection refused, errno = 61), address = raw.githubusercontent.com, port = 56560
[ 0.117s] HttpException: Not Found
Failed to retrieve the Flutter SDK from: https://flutter-io.cn/flutter_infra_release/releases/releases_macos.json
Fvm will use the value set on env FLUTTER_STORAGE_BASE_URL to check versions
if you are located in China, please see this page: https://flutter.dev/community/china
因为使用国内地址需要执行以下命令:
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
5.安装SDK指定版本:
fvm install 3.7.5
查看已安装的版本信息
fvm list
6.使用fvm配置全局SDK版本
fvm global 3.7.5
或
sudo fvm global 3.7.5
执行成功
xxx@MacBook-Air ~ % sudo fvm global 1.22.6
Flutter SDK: SDK Version : 1.22.6 is now global
执行失败:
xxxx@MacBook-Air ~ % sudo fvm global 1.22.6
Password:
Flutter SDK: SDK Version : 1.22.6 is now global
┌───────────────────────────────────────────────────────┐
│ ⚠ However your configured "flutter" path is incorrect │
└───────────────────────────────────────────────────────┘
CURRENT: No version is configured on path.
CHANGE TO: /Users/senf/fvm/default/bin
配置
export PATH="$HOME/fvm/default/bin:$PATH"
最后让环境变量生效
source ~/.zshrc
再次执行
fvm global 3.7.5
或
sudo fvm global 3.7.5
如果还是失败使用vim进行配置
vim ~/.zshrc
将环境变量写入到配置文件中
export PATH=$HOME/fvm/default/bin:$PATH
source ~/.zshrc
7.在VScode中使用Fvm
执行doctor命令
fvm flutter doctor
版本切换:
//切换到1.22.6
fvm use 1.22.6 --force
//切换到 3.7.5
fvm use 3.7.5 --force
8.Fvm常用命令
- config: 对 fvm 进行配置
- flutter: 对 Flutter 的命令进行代理
- install: 安装 Flutter 版本
- list: 查看已安装的 Flutter 版本
- releases: 查看 Flutter sdk 都有哪些发布的版本
- remove:删除已安装的某个 Flutter 的版本
- use: 选择你要使用的版本
- version: 查看安装 fvm 的版本
9.问题:
注意:
Fvm环境配置完成之后,如论如何切换版本VsCode Flutter版本都无法切换。
检查以下配置文件:
/Users/shen/Library/Application Support/Code/User/settings.json
将: "dart.flutterSdkPath": "/Users/shen.ef/fvm/versions/3.16.3" 注销掉