preface
The Node version is recommended to use the latest LTS version (currently 12.x), and you can use the current version (usually a larger version than the stable version).
The Node list version
NodeJS official website Download and install LTS or current version: NodeJS official website
The Node number version
Sometimes you need different versions of Node to run different projects,
A single version is limited, so the community has developed tools for multi-version management
nvm
NVM was originally implemented only for Linux and MacOS because it was written in shell scripts, but as it became more popular, it began to have peripherals, including windows-compatible derivative libraries
Linux/installed on macOS
$The curl - o - https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
#or
$Wget - qO - https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
#After the above execution is successful, you also need to write environment variables to your shell configuration file (in the user root directory).
# bash -> .bashrc
# zsh -> .zshrc
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 nvm
Copy the code
The Windows are installed on the
Download the NVM-Windows installation package to install it.
$NVM install 10.15.0Download, compile, and install the specified version of Node
$NVM use 10.15.0Switch to the specified version of Node
$ nvm aliasThe default 10.15.0Set the default shell version
Copy the code
See documentation for more NVM usage.
nvs
NVS supports full platform by default and is written in Node
Linux/installed on macOS
Declare a temporary variable
export NVS_HOME="$HOME/.nvs"
# clone warehouse
git clone https://github.com/jasongin/nvs "$NVS_HOME"
Execute the script installation
. "$NVS_HOME/nvs.sh" install
Copy the code
The Windows are installed on the
- The installationchocolatey, similar to MAC
brew
choco install nvs
Operation is also straightforward, as is NVM
$ nvs --help
NVS (Node Version Switcher) usage
nvs help <command> Get detailed help for a command
nvs install Initialize your profile for using NVS
nvs --version Display the NVS tool version
nvs menu Launch an interactive menu
nvs add <version> Download and extract a node version
nvs rm <version> Remove a node version
nvs migrate <fromver> [tover] Migrate global modules
nvs upgrade [fromver] Upgrade to latest patch of major version
nvs use [version] Use a node version inthe current shell nvs auto [on/off] Automatically switch based on cwd nvs run <ver> <js> [args...] Run a script using a node version nvsexec<ver> <exe> [args...] Run an executable using a node version nvswhich [version] Show the path to a node version binary
nvs ls [filter] List local node versions
nvs ls-remote [filter] List node versions available to download
nvs link [version] Link a version as the default
nvs unlink [version] Remove links to a default version
nvs alias [name] [value] Set or recall aliases forversions nvs remote [name] [uri] Set or recall download base URIs A version string consists of a semantic version number or version label ("lts" or "latest"), optionally preceeded by a remote name, optionally
followed by an architecture, separated by slashes.
Examples: "lts"."4.6.0"."6.3.1 / x86"."The node / 6.7.0 / x64"
Aliases may also be used anywhere in place of a version string.
Copy the code
$ nvs add lts Install the latest LTS
$ nvs use lts # Switch the specified node version
$ nvs link ltsSet the shell's default version
Copy the code
Source Node management
The company has set up a private NPM warehouse, which contains the necessary dependencies to run the project; NPM config can only be used to set local or global sources. The steps and operations are a bit cumbersome. For this situation, the community also came up with a tool for easy maintenance and quick switching: NRM
NRM installation
Install NRM globally
npm install -g nrm
Copy the code
Add the internal private warehouse address
Add a new NPM source,
NRM add h3npm # http://xxxxx/repository/npm-all/ company information, and desensitizationCopy the code
Switch the NPM source to the private bin
nrm use h3npm
Copy the code
Run the NRM ls command to view the current NPM source. * indicates the current NPM source
$ nrm lsNPM -- -- -- -- -- -- -- - https://registry.npmjs.org/ # NPM official source yarn -- -- -- -- -- - https://registry.yarnpkg.com/ # yarn source of official CNPM -- -- -- -- -- -- -- http://r.cnpmjs.org/ # CNPM source taobao - https://registry.npm.taobao.org/ # taobao official image source nj -- -- -- -- -- -- -- -- -- https://registry.nodejitsu.com/ # foreign official image source * h3npm -- -- -- -- -- - http://xxxxx/repository/npm-all/ # inside the company official image source (covers private library) h3 - authine - http://xxxxx/repository/npm-authine/ # private repositoriesCopy the code