macos -bash: yarn: command not found/-bash: cnpm: command not found

-bash: cnpm: command not found
-bash: yarn: command not found
-bash: xxxx: command not found
如上yarn/cnpm皆通用,前提是安装成功后报这个错误哈!

Error: EACCES: permission denied, mkdir 错误的同学请移步这篇文章 👉https://www.cnblogs.com/niceyoo/p/11703560.html

不同于Windows,我们使用了 sudo npm install -g yarn 安装了yarn,但是在终端打印版本或者是直接使用yarn却报如下错误信息:

-bash: yarn: command not found

其中一种原因:没有配置类似于Windows里的环境变量。

在终端输入:

open -e ~/.bash_profile

上方指令方式将通过记事本直接编辑的方式,或者是采用控制台的vim指令

vim ~/.bash_profile

如果采用vim的方式修改后记得执行 :wq 保存退出。


我们以open指令为例,在终端执行如下指令:

1、touch ~/.bash_profile

可跳过,touch的意思是没有就创建,.bash_profile为系统临时的环境变量

2、open -e ~/.bash_profile

open指令打开这个文件,如果提示没有权限 请在前面加上sudo,示例:sudo open -e ~/.bash_profile

3、找到安装的yarn目录

还记得安装yarn的目录吗?如果忘记了再执行安装一边呗,如下图所示(图片为网上的非本人打码):

4、在发开的bash_profile文件中输入 export PATH=$PATH:/usr/local/node_global/bin

注意:请将 /usr/local/node_global 替换为你的 yarn 存在的目录

5、source ~/.bash_profile

source 表示重新执行、刷新的意思

6、yarn -v


我创建了一个java相关的公众号,用来记录自己的学习之路,感兴趣的小伙伴可以关注一下微信公众号哈:niceyoo

posted @ 2019-10-23 12:34  niceyoo  阅读(3133)  评论(0编辑  收藏  举报