1、安装nodejs & npm
yum install -y nodejs npm
2、n – Interactively Manage Your Node.js Versions
npm install -g n
安装提示
[root@localhost ~]# n
find: ‘/usr/local/n/versions’: No such file or directory
Usage: n [options] [COMMAND] [args]
Commands:
n Display downloaded node versions and install selection
n latest Install the latest node release (downloading if necessary)
n lts Install the latest LTS node release (downloading if necessary)
n <version> Install node <version> (downloading if necessary)
n run <version> [args ...] Execute downloaded node <version> with [args ...]
n which <version> Output path for downloaded node <version>
n exec <vers> <cmd> [args...] Execute command with modified PATH, so downloaded node <version> and npm first
n rm <version ...> Remove the given downloaded version(s)
n prune Remove all downloaded versions except the installed version
n --latest Output the latest node version available
n --lts Output the latest LTS node version available
n ls Output downloaded versions
n ls-remote [version] Output matching versions available for download
n uninstall Remove the installed node and npm
Options:
-V, --version Output version of n
-h, --help Display help information
-p, --preserve Preserve npm and npx during install of node (requires rsync)
-q, --quiet Disable curl output (if available)
-d, --download Download only
-a, --arch Override system architecture
--all ls-remote displays all matches instead of last 20
--insecure Turn off certificate checking for https requests (may be needed from behind a proxy server)
--use-xz/--no-use-xz Override automatic detection of xz support and enable/disable use of xz compressed node downloads.
Aliases:
which: bin
run: use, as
ls: list
lsr: ls-remote
rm: -
lts: stable
latest: current
Versions:
Numeric version numbers can be complete or incomplete, with an optional leading 'v'.
Versions can also be specified by label, or codename,
and other downloadable releases by <remote-folder>/<version>
4.9.1, 8, v6.1 Numeric versions
lts Newest Long Term Support official release
latest, current Newest official release
auto Read version from file: .n-node-version, .node-version, .nvmrc, or package.json
engine Read version from package.json
boron, carbon Codenames for release streams
lts_latest node support aliases
and nightly, rc/10 et al
Error: no downloaded versions yet, see above help for commands
3、安装LTS版本
[root@localhost ~]# n lts
installing : node-v14.15.4
mkdir : /usr/local/n/versions/node/14.15.4
fetch : https://nodejs.org/dist/v14.15.4/node-v14.15.4-linux-x64.tar.xz
installed : v14.15.4 (with npm 6.14.10)
Note: the node command changed location and the old location may be remembered in your current shell.
old : /usr/bin/node
new : /usr/local/bin/node
To reset the command location hash either start a new shell, or execute PATH="$PATH"
[root@localhost ~]#
4、编辑环境变量:vim ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=/usr/local/bin/node:$PATH:$HOME/bin
export PATH
5、刷新配置
[root@localhost ~]# source ~/.bash_profile
[root@localhost ~]# node -v
v14.15.4