欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2022-07-12 13:22:54
...

博客主要更新地址:????https://www.cnblogs.com/niceyoo

-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的目录吗?如果忘记了再执行安装一边呗,如下图所示(图片为网上的非本人打码):

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

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

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

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

5、source ~/.bash_profile

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

6、yarn -v
macos -bash: yarn: command not found/-bash: cnpm: command not found


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

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