問題描述
關閉終端不記得我對 nvm/npm 的 .profile 更改 (Closing the terminal doesnt remember my .profile changes for nvm/npm)
我使用此說明安裝了 nvm/npm
https://www.digitalocean.com/community/tutorials/how‑to‑install‑node‑js‑on‑an‑ubuntu‑14‑04‑server (如何使用 NVM 安裝),但是每次我關閉終端時,它似乎都忘記了所有設置,我必須執行以下命令:source ~/.profile 然後選擇 npm 版本以使其再次運行。如何保持我的設置永久不變,或者至少在我的登錄會話期間保持不變?謝謝!(linuxmint 17)
參考解法
方法 1:
Sourcing ~/.profile
~/.profile is typically invoked from a login shell. See http://www.gnu.org/software/bash/manual/bashref.html#Bash‑Startup‑Files
Invoked as an interactive login shell, or with ‑‑login
When Bash is invoked as an interactive login shell, or as a non‑interactive shell with the ‑‑login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The ‑‑noprofile option may be used when the shell is started to inhibit this behavior.
Opening a terminal does not typically invoke a login shell. Have you tried rebooting/relogging? Additionally if either ~/.bash_profile
or ~/.bash_login
exist, then bash won't source ~/.profile
. There are two common ways to fix this:
Option 1
Move commands from the ~/.profile
file to ~/.bash_profile
Option 2
Source ~/.profile
from ~/.bash_profile
:
[[ ‑f ~/.profile ]] && . ~/.profile
Default Node version
You can configure a default node version by aliasing it to default
To set a default Node version to be used in any new shell, use the alias 'default':
nvm alias default node
See https://github.com/creationix/nvm
(by Jay12、Jonathan Rouleau)