Mac电脑flutter环境搭建
前言:
为什么我要写这篇文章,是因为官方文档它不香吗?
是的,它不太香,官方文档虽然详细,但是啰里八嗦的一堆堆,所以我参考了朋友的文章:
https://www.jianshu.com/p/4caecfa72962
当时写这篇文章,也是边学习搭建,边踩坑并记录,可能你们遇到的问题和我的不太一样,可以多参考一下其它小伙伴的分享,我这里就不啰嗦了。直接开始吧!!!
正文
1、查看brew有没有安装,打开终端,输入brew:

按下回车键:

当你看到很多brew开头的就说明已经安装了
2、那么接下来就是去官网下载
https://flutter.dev/docs/development/tools/sdk/releases?tab=macos
选择最新的版本,点击它下载

然后把下载的SDK包丢到文稿下面,会看到一个flutter文件夹(文件夹名字看你高兴取,第一次建议你跟着我的步骤来):

3、然后是将SDK和电脑环境关联起来,执行命令vim ~/.bash_profile:


按 i 键进入编辑状态,配置相关信息,写入
export PATH=~/Documents/flutter/bin:$PATH
export PUB_HOSTED_URL=https://pub.flutter-io.cn
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn


编辑完了怎么保存退出呢?按一下键盘左上角的esc,再按一下组合键“ : + W + Q”:

再按一下回车键enter即可退出
4、紧接着输入命令并回车键:source ~/.bash_profile
再输入flutter -h
如果你发现返回flutter: command not found

那就输入vim ~/.zshrc
按 i 键进入编辑状态,配置相关信息,写入
export PATH="PATH:$HOME/.rvm/bin"
source ~/.bash_profile

保存退出操作:按一下esc,再按住组合键“ : + W + Q”
到了这一步可以执行命令flutter -h,如果报错

那就执行一下命令:source ~/.bash_profile
这一句的作用是让前面的vim ~/.bash_profile文件生效,每次修改了这个文件都建议执行一遍命令source ~/.bash_profile
如果还是不行,那就执行vim ~/.bash_profile并检查一下填写的路径,实在不行就改成绝对路径:

再次执行flutter -h


5、接下来执行命令flutter doctor

至此,就完成了Mac下flutter开发环境的搭建。
追述:
brew 全称Homebrew, 是Mac OSX上的软件包管理工具,brew 可以用一条命令,就可以在mac上安装、卸载、更新各种软件包。具体安装命令可以访问官网首页
这边提供了brew安装过程中可能遇到的bug及解决方案:
https://www.jianshu.com/p/5736f273df13