Installing and Updating
Install & Update Script
To install or update nvm, you should run the install script. To do that, you may either download and run the script manually, or use the following cURL or Wget command:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bashwget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bashRunning either of the above commands downloads a script and runs it. The script clones the nvm repository to ~/.nvm, and attempts to add the source lines from the snippet below to the correct profile file (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc).
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvmAdditional Notes
If the environment variable
$XDG_CONFIG_HOMEis present, it will place thenvmfiles there.You can add
--no-useto the end of the above script (...nvm.sh --no-use) to postpone usingnvmuntil you manuallyuseit.You can customize the install source, directory, profile, and version using the
NVM_SOURCE,NVM_DIR,PROFILE, andNODE_VERSIONvariables. Eg:curl ... | NVM_DIR="path/to/nvm". Ensure that theNVM_DIRdoes not contain a trailing slash.The installer can use
git,curl, orwgetto downloadnvm, whichever is available.
Troubleshooting on Linux
On Linux, after running the install script, if you get nvm: command not found or see no feedback from your terminal after you type command -v nvm, simply close your current terminal, open a new terminal, and try verifying again.
Troubleshooting on macOS
Since OS X 10.9, /usr/bin/git has been preset by Xcode command line tools, which means we can't properly detect if Git is installed or not. You need to manually install the Xcode command line tools before running the install script, otherwise, it'll fail. (see #1782)
If you get nvm: command not found after running the install script, one of the following might be the reason:
Since macOS 10.15, the default shell is
zshand nvm will look for.zshrcto update, none is installed by default. Create one withtouch ~/.zshrcand run the install script again.If you use bash, the previous default shell, run
touch ~/.bash_profileto create the necessary profile file if it does not exist.You might need to restart your terminal instance or run
. ~/.nvm/nvm.sh. Restarting your terminal/opening a new tab/window, or running the source command will load the command and the new configuration.
If the above doesn't fix the problem, you may try the following:
If you use bash, it may be that your
.bash_profile(or~/.profile) does not source your~/.bashrcproperly. You could fix this by addingsource ~/<your_profile_file>to it or follow the next step below.Try adding the snippet from the install section, that finds the correct nvm directory and loads nvm, to your usual profile (
~/.bash_profile,~/.zshrc,~/.profile, or~/.bashrc).For more information about this issue and possible workarounds, please refer here
Usage
To download, compile, and install the latest release of node, do this:
nvm install node # "node" is an alias for the latest versionTo install a specific version of node:
nvm install 6.14.4 # or 10.10.0, 8.9.1, etcThe first version installed becomes the default. New shells will start with the default version of node (e.g., nvm alias default).
You can list available versions using ls-remote:
nvm ls-remoteAnd then in any new shell just use the installed version:
nvm use nodeOr you can just run it:
nvm run node --versionOr, you can run any arbitrary command in a subshell with the desired version of node:
nvm exec 4.2 node --versionYou can also get the path to the executable to where it was installed:
nvm which 5.0In place of a version pointer like "0.10" or "5.0" or "4.2.1", you can use the following special default aliases with nvm install, nvm use, nvm run, nvm exec, nvm which, etc:
node: this installs the latest version ofnodeiojs: this installs the latest version ofio.jsstable: this alias is deprecated, and only truly applies tonodev0.12and earlier. Currently, this is an alias fornode.unstable: this alias points tonodev0.11- the last "unstable" node release, since post-1.0, all node versions are stable. (in SemVer, versions communicate breakage, not stability).
Long-term Support
Node has a schedule for long-term support (LTS) You can reference LTS versions in aliases and .nvmrc files with the notation lts/* for the latest LTS, and lts/argon for LTS releases from the "argon" line, for example. In addition, the following commands support LTS arguments:
nvm install --lts/nvm install --lts=argon/nvm install 'lts/*'/nvm install lts/argonnvm uninstall --lts/nvm uninstall --lts=argon/nvm uninstall 'lts/*'/nvm uninstall lts/argonnvm use --lts/nvm use --lts=argon/nvm use 'lts/*'/nvm use lts/argonnvm exec --lts/nvm exec --lts=argon/nvm exec 'lts/*'/nvm exec lts/argonnvm run --lts/nvm run --lts=argon/nvm run 'lts/*'/nvm run lts/argonnvm ls-remote --lts/nvm ls-remote --lts=argonnvm ls-remote 'lts/*'/nvm ls-remote lts/argonnvm version-remote --lts/nvm version-remote --lts=argon/nvm version-remote 'lts/*'/nvm version-remote lts/argon
Any time your local copy of nvm connects to https://nodejs.org, it will re-create the appropriate local aliases for all available LTS lines. These aliases (stored under $NVM_DIR/alias/lts), are managed by nvm, and you should not modify, remove, or create these files - expect your changes to be undone, and expect meddling with these files to cause bugs that will likely not be supported.
To get the latest LTS version of node and migrate your existing installed packages, use
nvm install 'lts/*' --reinstall-packages-from=current
No comments:
Post a Comment