安裝指令:
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
這個網(wǎng)址估計是被墻了,所以一直顯示的訪問超時。
所以去了
https://github.com/nvm-sh/nvm
看了readme找到了install.sh的源代碼
網(wǎng)址:
https://github.com/nvm-sh/nvm/blob/v0.35.1/install.sh
復(fù)制下來保存在任意的文件夾,通過終端來執(zhí)行即可。
./nvm_install.sh
但是執(zhí)行這個語句的時候,報了一個錯,錯誤顯示
-bash: ./nvm_install.sh: Permission denied
查閱資料后知道:需要修改.sh文件的權(quán)限。
使用命令:
chmod u+x nvm_install.sh即可。
執(zhí)行完之后,顯示安裝成功,重啟終端就可以了,但是發(fā)現(xiàn)重啟終端以后沒有還是報command not found
查看了nvm的readme以后,發(fā)現(xiàn)這一段話。
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.
于是我執(zhí)行了 touch ~/.bash_profile 并再次運行了 ./nvm_install.sh,執(zhí)行完畢,重啟終端,輸入nvm。成功,以上
touch命令
一、用于把已存在文件的時間標(biāo)簽更新為系統(tǒng)當(dāng)前的時間(默認(rèn)方式),它們的數(shù)據(jù)將原封不動地保留下來;
二、用來創(chuàng)建新的空文件。
執(zhí)行nvm install stable時遇到下載超時的問題,解決方法:
touch ~/.zshrc ##創(chuàng)建.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
更新環(huán)境變量
source ~/.zshrc
運行
nvm install stable
執(zhí)行成功