Use Nvm to Install Node.js
Node.js:https://nodejs.org
Node.js lets developers use JavaScript to write command line tools and for server-side scripting—running scripts server-side to produce dynamic web page content before the page is sent to the user’s web browser.
Install or Update NVM
Install/Update Use Script
1 | curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash |
The script clones the nvm repository to ~/.nvm
and adds the source line to your profile (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc).
Note: If the environment variable $XDG_CONFIG_HOME
is present, it will place the nvm files there.
1 | export NVM_DIR="${XDG_CONFIG_HOME/:-$HOME/.}nvm" |
After running the install script, close current terminal and open a new terminal,
Install/Update Use Git
- Install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15:~$ export NVM_DIR="$HOME/.nvm" && (
git clone https://github.com/nvm-sh/nvm.git "$NVM_DIR"
cd "$NVM_DIR"
git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)`
) && \. "$NVM_DIR/nvm.sh"
...
...
# add these lines to `~/.bashrc`, `~/.profile`, or `~/.zshrc` file
# to have it automatically sourced upon login
:~/.nvm$ cat >> ~/.bashrc << EOF
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
# [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" --no-use
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
EOF - Update
1
2
3
4
5(
cd "$NVM_DIR"
git fetch --tags origin
git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)`
) && \. "$NVM_DIR/nvm.sh"
Install Node Use NVM
download/compile/install the latest release of Node
1 | :~$ cd ~/.nvm |
List Available Node Versions
1 | nvm ls-remote |
Install a specific version of Node
1 | nvm install 11.14 |
Use Command Npm of Node
1 | :~$ nvm use default |
Global Packages
- Update all global packages
1
2
3
4
5:~$ cd "$NVM_DIR"
# Method One
:~/.nvm$ npm -g install
# Method Two
:~/.nvm$ npm -g update - lookup which packages need to be updated
1
2
3
4:~$ npm -g outdated
Package Current Wanted Latest Location
appium 1.5.2 1.5.3 1.5.3
bower 1.7.0 1.7.9 1.7.9 - Update the global program to specify version
1
2
3
4
5
6:~$ cd "$NVM_DIR"
# Method One
:~/.nvm$ npm -g install npm@6.9.0
:~/.nvm$ npm -g install npm@next
# Method Two
:~/.nvm$ npm -g update npm@6.9.0 - uninstall global package
1
2:~$ cd "$NVM_DIR"
:~/.nvm$ npm -g uninstall <package name> - Audit security of the global packages
1
2:~/.nvm$ npm audit
:~/.nvm$ npm audit fix
Local Packages
- Update all local packages
1
2
3
4
5:~$ cd ~/.hexo
# Method One
:~/.hexo$ npm install
# Method Two
:~/.hexo$ npm update - lookup which local packages need to be updated
1
2
3:~/.hexo$ npm outdated
Package Current Wanted Latest Location
requirejs 2.1.22 2.2.0 2.2.0 - Update the local packages to specify version
1
2
3
4
5:~$ cd "$NVM_DIR"
# Method One
:~/.hexo$ npm install requirejs@2.2.0
# Method Two
:~/.hexo$ npm install requirejs@next - uninstall the local package
1
:~/.hexo$ npm uninstall <package name>
- Audit security of the local packages
1
2:~/.hexo$ npm audit
:~/.hexo$ npm audit fix
Prefence:
Github_NVM