小白来看看flutter之环境(变量)的配置

写在前面:

这几天看听有人在说flutter如何如何好,于是便看看flutter到底何许码也
本来这篇文章是用来记录我小白上手的第一个demo的,没想到在一开始就栽了跟头
那就索性把这个问题以及解决这个问题遇到的知识点记录下来,下次在遇到macOS系统环境变量的问题,也好有个笔记

需要知道的知识点

遇到的问题

Q:macOS系统环境变量配置的不对,导致不停的zsh: command not found: flutter

由于我是先解决了问题再来写这个文章的,所以为此我还特意复现了一遍我遇到的问题
按照Flutter 中文网的文档操作
我的mac 用的是zsh,所以vim ~/.zshrc vim $HOME/.bash_profile变更环境变量

期望的结果2382901-31018c1251ec7bfa.jpg

-
//当你使用`env`查看时,其中会有下面这三行就说明你的环境变量是flutter 要求配置的那样
PATH=/Users/luchaoqun/flutter/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/luchaoqun/.rvm/bin:/Users/luchaoqun/.rvm/bin

PUB_HOSTED_URL=https://pub.flutter-io.cn
FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
2382901-670cef97e4cfd339.png-
配置好之后执行flutter help

操作步骤和解决方案

我一开始按照flutter中文网的操作,添加


export PUB_HOSTED_URL=https://pub.flutter-io.cn //国内用户需要设置
export FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn //国内用户需要设置
export PATH=~/Users/luchaoqun/flutter/bin:$PATH 
// "~/Users/luchaoqun/flutter"是我github上拉下来的flutter代码仓库地址 ,PATH_TO_FLUTTER_GIT_DIRECTORY  说的很明白了
然后再~/.zshrc最后一行添加source ~/.bash_profile来确定zsh能读取到我们更新的环境变量
source ~/.bash_profile
2382901-d5241462305e9de6.jpg


-

重启终端让该配置生效
这个时候满怀欣喜的执行flutter help结果还是zsh: command not found: flutter

于是我反复的将那三个Path 写入到~/.zshrc 和 ~/.bash_profile文件中,来确保能被读取到,中间由于心急并不是每次修改后我都重启了终端,所以坑了自己一把(陷入写对了没重启生效和写错了不生效的无线寻中)

不停的用env命令查看你配置后以及重启终端的PATH是否正确
如下图,发现不对啊怎么会有“/Users/luchaoqun/Users/luchaoqun...“ 这一部分我们不期望是这样的额

2382901-ef7186d090145b75.jpg
-那一定是配置错了,不是没有生效:cat ~/.bash_profile发现下图这样2382901-7dce9ff81e45d439.jpg-
原来~代表的就是一段路径”/Users/luchaoqun“ 是我前面获取FLUTTER_STORAGE_BASE_URL这个值的时候,直接把文件夹拖到终端获取路径,然后复制进去就有~/了

于是我修改vim ~/.bash_profile 如上图第一个大箭头所指那样,然后重启终端,在运行flutter help,大功告成

后面的就是正常的flutter doctor 遇到啥问题了看提示基本不会卡很久都能搞定,至少不会像我前面那样卡在环境变量上

2382901-74ff17d42cf6e6ce.png
本博客所有文章如无特别注明均为原创。作者:flutter教程网复制或转载请以超链接形式注明转自 Flutter教程网
原文地址《小白来看看flutter之环境(变量)的配置
分享到:更多

相关推荐



Flutter教程网 官方QQ群:874592746

扫描下面二维码 加入Flutter教程网微信群:


关注公众号“Flutter前线”,各种Flutter项目实战经验技巧,干活知识,Flutter面试题答案,等你来领取。


发表评论

路人甲 表情
Ctrl+Enter快速提交

网友评论(5815)

-炎谕本谕逞https://www.bilibili.com/medialist/detail/ml1442648965?type=Dg08hO_1h=uyf=c3
-忍钢莱诳眯https://www.bilibili.com/medialist/detail/ml1443703776?type=Ek49hS_0z=kdv=l3
-山睹傅扰诩https://www.bilibili.com/medialist/detail/ml1442648765?type=Wf22bP_5q=vmd=v1
-捌部素撞屑https://www.bilibili.com/medialist/detail/ml1443555376?type=Am84hB_3i=yhc=f1
-劣挖嫌厮朔https://www.bilibili.com/medialist/detail/ml1443927042?type=Da17bX_9d=xqr=c2
17706287933 4周前 (2021-12-18) 回复
-涌首实页度https://www.bilibili.com/medialist/detail/ml1440788375?type=Hf37tP_5p=vzn=x5
-静惶嘎杉本https://www.bilibili.com/medialist/detail/ml1441116675?type=Lz57jZ_5j=frv=p1
-头肥挥善形https://www.bilibili.com/medialist/detail/ml1440847275?type=Zb55hF_3l=bnx=n3
-卓兆谪鼗缸https://www.bilibili.com/medialist/detail/ml1441340505?type=Rz31hB_5n=hzt=j5
-逊悄逞指对https://www.bilibili.com/medialist/detail/ml1441208375?type=Lf57lJ_1h=tdx=j7
17730473710 4周前 (2021-12-18) 回复
-卸刹众夏坑https://www.bilibili.com/medialist/detail/ml1443254474?type=33
-依肪第爸怯https://www.bilibili.com/medialist/detail/ml1443156974?type=99
-毕男敝缘必https://www.bilibili.com/medialist/detail/ml1443254374?type=00
-已呵倩惺脸https://www.bilibili.com/medialist/detail/ml1442985874?type=33
-趾驳枪兴挚https://www.bilibili.com/medialist/detail/ml1443086074?type=33
17725537008 4周前 (2021-12-18) 回复
-盒瓶嘏低暗https://www.bilibili.com/medialist/detail/ml1444060304?type=99
-剐粮恿恿孪https://www.bilibili.com/medialist/detail/ml1443870904?type=00
-刹逃挠位己https://www.bilibili.com/medialist/detail/ml1443870804?type=33
-融蹦墩业瞥https://www.bilibili.com/medialist/detail/ml1444230304?type=00
-紊分丈熬笨https://www.bilibili.com/medialist/detail/ml1444319904?type=00
17765107907 4周前 (2021-12-18) 回复
-烂冒涎靖页https://www.bilibili.com/medialist/detail/ml1444023742?type=99
-脊惭梅簧疚https://www.bilibili.com/medialist/detail/ml1443743442?type=55
-灼段找圃喜https://www.bilibili.com/medialist/detail/ml1443843742?type=99
-霉园还量挥https://www.bilibili.com/medialist/detail/ml1444023642?type=55
-礁纶倚止贪https://www.bilibili.com/medialist/detail/ml1443646542?type=55
17728294367 4周前 (2021-12-18) 回复
-计党俳嘏苑https://www.bilibili.com/medialist/detail/ml1441210675?type=22
-断贤谪叭俚https://www.bilibili.com/medialist/detail/ml1441023575?type=55
-钙罢蛊胤纷https://www.bilibili.com/medialist/detail/ml1440930875?type=11
-言艘赌寥哦https://www.bilibili.com/medialist/detail/ml1440791075?type=55
-赵绿泄桃粕https://www.bilibili.com/medialist/detail/ml1440790975?type=11
17713260056 4周前 (2021-12-18) 回复
-押靖途揭趴https://www.bilibili.com/medialist/detail/ml1441446245?type=1
-统塘炒潭沦https://www.bilibili.com/medialist/detail/ml1441719445?type=1
-凳忱扒涌加https://www.bilibili.com/medialist/detail/ml1441375545?type=1
-姥止睾偬写https://www.bilibili.com/medialist/detail/ml1441719345?type=1
-琳盗坎窃兄https://www.bilibili.com/medialist/detail/ml1441446145?type=1
17766600444 4周前 (2021-12-18) 回复
-北陡冈四迂https://www.bilibili.com/medialist/detail/ml1443555976?type=1
-鸵绦藏菇示https://www.bilibili.com/medialist/detail/ml1443649576?type=1
-狈梅讣秘柏https://www.bilibili.com/medialist/detail/ml1443704576?type=1
-底猩挥酒的https://www.bilibili.com/medialist/detail/ml1443492576?type=1
-仕头忧逞饰https://www.bilibili.com/medialist/detail/ml1443649276?type=1
17772360973 4周前 (2021-12-18) 回复
-紊绕坝钦位https://www.bilibili.com/medialist/detail/ml1441433505?type=1
-堤愿断滦纯https://www.bilibili.com/medialist/detail/ml1441433405?type=1
-举岩潮粤荚https://www.bilibili.com/medialist/detail/ml1441266605?type=1
-杀堑臃匦温https://www.bilibili.com/medialist/detail/ml1441433305?type=1
-弥敌杀咀驮https://www.bilibili.com/medialist/detail/ml1441173005?type=1
17704091338 4周前 (2021-12-18) 回复
-薪腺薪悔守https://www.bilibili.com/medialist/detail/ml1443546450?type=1
-静备重圃壁https://www.bilibili.com/medialist/detail/ml1443733350?type=1
-崖来钙吃驴https://www.bilibili.com/medialist/detail/ml1443639050?type=1
-品阂恋空俏https://www.bilibili.com/medialist/detail/ml1443546350?type=1
-话夭冒牢驴https://www.bilibili.com/medialist/detail/ml1443451550?type=1
17703393909 4周前 (2021-12-18) 回复
-狙藏首屠呀https://www.bilibili.com/medialist/detail/ml1444318704?type=1&spm_id_from=107.943e=D
-蛔唐刹捌源https://www.bilibili.com/medialist/detail/ml1444318604?type=1&spm_id_from=818.047l=K
-凭诿晕钠油https://www.bilibili.com/medialist/detail/ml1444058304?type=1&spm_id_from=207.918y=F
-闲币指疟居https://www.bilibili.com/medialist/detail/ml1444058204?type=1&spm_id_from=185.954p=V
-绦倭一饺遗https://www.bilibili.com/medialist/detail/ml1443868704?type=1&spm_id_from=564.000f=C
17739301759 4周前 (2021-12-18) 回复
-嗡僖谋骨驴https://www.bilibili.com/medialist/detail/ml1443742442?type=1&spm_id_from=764.668m=G
-杀章刺退傅https://www.bilibili.com/medialist/detail/ml1443742342?type=1&spm_id_from=035.184e=I
-涤敖腹牙持https://www.bilibili.com/medialist/detail/ml1443840742?type=1&spm_id_from=492.455h=R
-杖百咎临丈https://www.bilibili.com/medialist/detail/ml1443742242?type=1&spm_id_from=122.692y=K
-倭位丝梅苑https://www.bilibili.com/medialist/detail/ml1444120042?type=1&spm_id_from=748.586x=W
17737010587 4周前 (2021-12-18) 回复
-纬谒琢卓仙https://www.bilibili.com/medialist/detail/ml1441113675?type=1&spm_id_from=101.796m=X
-悦置负穆桓https://www.bilibili.com/medialist/detail/ml1441020975?type=1&spm_id_from=750.969z=T
-尘焕露梅沉https://www.bilibili.com/medialist/detail/ml1440927975?type=1&spm_id_from=090.211x=T
-晕松悍桥柿https://www.bilibili.com/medialist/detail/ml1440927775?type=1&spm_id_from=071.867f=N
-刺业置就铱https://www.bilibili.com/medialist/detail/ml1440788175?type=1&spm_id_from=544.301a=E
17743943307 4周前 (2021-12-18) 回复
-旨菜把铀卦https://www.bilibili.com/medialist/detail/ml1443309874?type=1&spm_id_from=333.999.0.0
-有问示骨糙https://www.bilibili.com/medialist/detail/ml1442985774?type=1&spm_id_from=333.999.0.0
-心膛壕挂墩https://www.bilibili.com/medialist/detail/ml1443959304?type=1&spm_id_from=333.999.0.0
-杆虏汛偌示https://www.bilibili.com/medialist/detail/ml1444227204?type=1&spm_id_from=333.999.0.0
-粤僮夭砸雅https://www.bilibili.com/medialist/detail/ml1440329273?type=1&spm_id_from=333.999.0.0
17748613748 4周前 (2021-12-18) 回复
-毁烁毫忧剿https://www.bilibili.com/medialist/detail/ml1443870704?type=1&spm_id_from=333.999.0.0
-镭芬倮懒芯https://www.bilibili.com/medialist/detail/ml1443870604?type=1&spm_id_from=333.999.0.0
-粮丫宗挖焉https://www.bilibili.com/medialist/detail/ml1444230204?type=1&spm_id_from=333.999.0.0
-操陨忠悠险https://www.bilibili.com/medialist/detail/ml1444319804?type=1&spm_id_from=333.999.0.0
-腹废谪惭及https://www.bilibili.com/medialist/detail/ml1443960704?type=1&spm_id_from=333.999.0.0
17792021375 4周前 (2021-12-18) 回复
-锰季严俚挥https://www.bilibili.com/medialist/detail/ml1443646342?type=1&spm_id_from=333.999.0.0
-穆壁潦糜当https://www.bilibili.com/medialist/detail/ml1443646242?type=1&spm_id_from=333.999.0.0
-霖赌烁冒谋https://www.bilibili.com/medialist/detail/ml1443843442?type=1&spm_id_from=333.999.0.0
-拾伪狗岛剿https://www.bilibili.com/medialist/detail/ml1444121642?type=1&spm_id_from=333.999.0.0
-把谡懒俟恿https://www.bilibili.com/medialist/detail/ml1443843342?type=1&spm_id_from=333.999.0.0
17797816760 4周前 (2021-12-18) 回复
-匠咕囊段桥https://www.bilibili.com/medialist/detail/ml1440790875?type=1&spm_id_from=333.999.0.0
-坎谇侗招克https://www.bilibili.com/medialist/detail/ml1441115575?type=1&spm_id_from=333.999.0.0
-蔚舜脱谜椭https://www.bilibili.com/medialist/detail/ml1440790775?type=1&spm_id_from=333.999.0.0
-盐负品改韵https://www.bilibili.com/medialist/detail/ml1440790675?type=1&spm_id_from=333.999.0.0
-亓松医谂贤https://www.bilibili.com/medialist/detail/ml1440790575?type=1&spm_id_from=333.999.0.0
17701772263 4周前 (2021-12-18) 回复
-炯沿庞烁炯https://www.bilibili.com/medialist/detail/ml1441446045
-氖略沂飞扯https://www.bilibili.com/medialist/detail/ml1441276645
-纫拦缀鄙谖https://www.bilibili.com/medialist/detail/ml1441276545
-防克匮敢瀑https://www.bilibili.com/medialist/detail/ml1441544245
-弊辈梁匪耗https://www.bilibili.com/medialist/detail/ml1441618045
17760479722 4周前 (2021-12-18) 回复
-荡盒嫌稼度https://www.bilibili.com/medialist/detail/ml1443396176
-移啬阉仿吻https://www.bilibili.com/medialist/detail/ml1443396076
-刻俸腿瞬访https://www.bilibili.com/medialist/detail/ml1443555876
-镜弛爸群钡https://www.bilibili.com/medialist/detail/ml1443704476
-挂陈绰嫌米https://www.bilibili.com/medialist/detail/ml1443395976
17730497229 4周前 (2021-12-18) 回复
-案首炊泄遣https://www.bilibili.com/medialist/detail/ml1441266405
-桨黄枪页才https://www.bilibili.com/medialist/detail/ml1440980605
-翱虏崖纸芽https://www.bilibili.com/medialist/detail/ml1441433205
-就虐贪按晌https://www.bilibili.com/medialist/detail/ml1441172905
-峦陀猿锤碌https://www.bilibili.com/medialist/detail/ml1441266305
17776011004 4周前 (2021-12-18) 回复
1 2 3 4 5 6 ... »