安装指令:
curl -o-https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.1/install.sh | bash
但是
https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.1/install.sh
这个网址估计是被墙了,所以一直显示的访问超时。
所以去了
https://github.com/nvm-sh/nvm
看了readme找到了install.sh的源代码
网址:
https://github.com/nvm-sh/nvm/blob/v0.35.1/install.sh
复制下来保存在任意的文件夹,通过终端来执行即可。
./nvm_install.sh
但是执行这个语句的时候,报了一个错,错误显示
-bash: ./nvm_install.sh: Permission denied
查阅资料后知道:需要修改.sh文件的权限。
使用命令:
chmod u+x nvm_install.sh即可。
执行完之后,显示安装成功,重启终端就可以了,但是发现重启终端以后没有还是报command not found
查看了nvm的readme以后,发现这一段话。
On OS X, if you get nvm: command not found after running the install script,
one of the following might be the reason:
- Your system may not have a .bash_profile file where the command is set up.
Create one with touch ~/.bash_profile and run the install script again- You might need to restart your terminal instance.
Try opening a new tab/window in your terminal and retry.
于是我执行了 touch ~/.bash_profile 并再次运行了 ./nvm_install.sh,执行完毕,重启终端,输入nvm。成功,以上
touch命令
一、用于把已存在文件的时间标签更新为系统当前的时间(默认方式),它们的数据将原封不动地保留下来;
二、用来创建新的空文件。
执行nvm install stable时遇到下载超时的问题,解决方法:
touch ~/.zshrc ##创建.zshrc文件
open ~/.zshrc ##打开.zshrc文件
在.zshrc文件添加两行代码
export NVM_NODEJS_ORG_MIRROR=http://npm.taobao.org/mirrors/node
export NVM_IOJS_ORG_MIRROR=http://npm.taobao.org/mirrors/iojs
更新环境变量
source ~/.zshrc
运行
nvm install stable
执行成功