本文翻譯自:nvm keeps “forgetting” node in new terminal session
Upon using a new terminal session in OS X, nvm
forgets the node version and defaults to nothing: 在OS X中使用新的終端會話時, nvm
忘記節點版本並默認爲nvm
:
$ nvm ls
: $ nvm ls
:
.nvm
v0.11.12
v0.11.13
I have to keep hitting nvm use v.0.11.13
in every session: 我必須在每個會話中繼續nvm use v.0.11.13
:
.nvm
v0.11.12
-> v0.11.13
I've tried both the brew
install, as well as the official installation script. 我已經嘗試了brew
安裝,以及官方安裝腳本。
My .profile
for the brew version: 我的.profile
爲brew版本:
#nvm
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh
And for the install.sh script: 對於install.sh腳本:
$ curl https://raw.githubusercontent.com/creationix/nvm/v0.10.0/install.sh | bash
#nvm
export NVM_DIR="/Users/farhad/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
Any clue to what I'm doing wrong? 我有什麼不對的任何線索?
#1樓
參考:https://stackoom.com/question/1f9kT/nvm在新的終端會話中保持-遺忘-節點
#2樓
Try nvm alias default
. 嘗試使用nvm alias default
。 For example: 例如:
$ nvm alias default 0.12.7
This sets the default node version in your shell. 這將在shell中設置默認節點版本。 Then verify that the change persists by closing the shell window, opening a new one, then: node --version
然後通過關閉shell窗口,打開一個新窗口,然後: node --version
驗證更改是否仍然存在
#3樓
nvm does its job by changing the PATH variable, so you need to make sure you aren't somehow changing your PATH to something else after sourcing the nvm.sh script. nvm通過更改PATH變量來完成它的工作,所以你需要確保在獲取nvm.sh腳本後你不會以某種方式將PATH更改爲其他東西。
In my case, nvm.sh was being called in .bashrc but then the PATH variable was getting updated in .bash_profile which caused my session to find the system node before the nvm node. 在我的例子中,在.bashrc中調用了nvm.sh,然後在.bash_profile中更新了PATH變量,導致我的會話在nvm節點之前找到了系統節點。
#4樓
別名到node
本身以避免更新默認別名以及稍後的節點版本更新。
nvm alias default node
#5樓
The top rated solutions didn't seem to work for me. 最受好評的解決方案似乎對我不起作用。 My solution is below: 我的解決方案如下:
- Uninstall nvm completely using homebrew:
brew uninstall nvm
使用homebrew:brew uninstall nvm
完全brew uninstall nvm
- Reinstall
brew install nvm
重新安裝brew install nvm
In Terminal, follow the steps below(these are also listed when installing nvm via homebrew): 在終端中,請按照以下步驟(通過自制軟件安裝nvm時也會列出這些步驟):
mkdir ~/.nvm cp $(brew --prefix nvm)/nvm-exec ~/.nvm/ export NVM_DIR=~/.nvm source $(brew --prefix nvm)/nvm.sh
The steps outlined above will add NVM's working directory to your $HOME path, copy nvm-exec to NVM's working directory and add to $HOME/.bashrc, $HOME/.zshrc, or your shell's equivalent configuration file.(again taken from whats listed on an NVM install using homebrew) 上面列出的步驟將NVM的工作目錄添加到$ HOME路徑,將nvm-exec複製到NVM的工作目錄並添加到$ HOME / .bashrc,$ HOME / .zshrc或shell的等效配置文件。(再次從什麼中獲取)在使用自制軟件的NVM安裝中列出)
#6樓
This question has mentioned for the OSX, but it happened to me in my linux OS. 這個問題已經提到了OSX,但它發生在我的Linux操作系統中。 I tried using nvm alias default <version>
but for each new terminal session the used node version was forgotten. 我嘗試使用nvm alias default <version>
但是對於每個新的終端會話,忘記了使用的節點版本。 so, here is the solution that i figured out. 所以,這是我想出的解決方案。
make sure to set a default alias for node version ,put the following code in .bashrc, and source .bashrc
. 確保爲節點版本設置默認別名 ,將以下代碼放在.bashrc中,並將source .bashrc
代碼放在source .bashrc
。
export NVM_DIR="/home/bonnie/.nvm"
## If the file exists and is not empty
if [ -s "$NVM_DIR/nvm.sh" ]; then
## Source it
source "$NVM_DIR/nvm.sh"
fi
NODE_DEFAULT_VERSION=$(<"$NVM_DIR/alias/default")
export PATH="$NVM_DIR/versions/node/$NODE_DEFAULT_VERSION/bin":$PATH