安裝nvm時遇到的坑(MacOS)

安裝指令:

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:

  1. 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
  2. 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í)行成功

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容