Linux环境下安装Nodejs
下载地址:https://nodejs.org/zh-cn/download/package-manager
一、使用压缩包自定义安装
上述链接下载好对应版本的软件包后,我存放到 /evn/nodejs 目录下(根据自己实际情况设置)
- 设置软链接
 
            
            
              bash
              
              
            
          
          sudo ln -s /evn/nodejs/node-v16.18.0-linux-x64/bin/npm /usr/local/bin/ 
sudo ln -s /evn/nodejs/node-v16.18.0-linux-x64/bin/node /usr/local/bin/
        - 设置镜像源地址
 
            
            
              bash
              
              
            
          
          npm config set registry https://registry.npmmirror.com/
        - 查看地址是否设置成功
 
            
            
              bash
              
              
            
          
          npm config get registry
        - 安装cnpm
 
            
            
              bash
              
              
            
          
          npm install -g cnpm --registry=https://registry.npmmirror.com/
        - 设置软连接
 
            
            
              bash
              
              
            
          
          sudo ln -s /evn/nodejs/node-v16.18.0-linux-x64/bin/cnpm /usr/local/bin/
        二、使用nvm命令安装
            
            
              bash
              
              
            
          
          # installs nvm (Node Version Manager)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
# download and install Node.js (you may need to restart the terminal)
nvm install 20
# verifies the right Node.js version is in the environment
node -v # should print `v20.15.1`
# verifies the right NPM version is in the environment
npm -v # should print `10.7.0`
        相关命令
- nvm list #查看已经安装的版本
 - nvm list installed #查看已经安装的版本
 - nvm list available #查看网络可以安装的版本
 - nvm version #查看当前的版本
 - nvm install #安装最新版本
 - nvm nvm use #切换使用指定的版本
 - node nvm ls# 列出所有版本 nvm current显示当前版本
 - nvm alias #给不同的版本号添加别名
 - nvm unalias #删除已定义的别名
 - nvm reinstall-packages 在#当前版本node环境下,重新全局安装指定版本号的npm包
 - nvm on #打开nodejs控制
 - nvm off #关闭nodejs控制
 - nvm proxy #查看设置与代理
 - nvm node_mirror [url] #设置或者查看setting.txt中的node_mirror,如果不设置的默认是 Index of /dist/
 - nvm npm_mirror [url] #设置或者查看setting.txt中的 npm_mirror,如果不设置的话默认的是: https://github.com/npm/npm/archive/
 - nvm uninstall #卸载制定的版本
 - nvm use [version] [arch] #切换制定的node版本和位数
 - nvm root [path] #设置和查看root路径
 
三、使用fnm命令安装
            
            
              bash
              
              
            
          
          # installs fnm (Fast Node Manager)
curl -fsSL https://fnm.vercel.app/install | bash
# download and install Node.js
fnm use --install-if-missing 20
# verifies the right Node.js version is in the environment
node -v # should print `v20.15.1`
# verifies the right NPM version is in the environment
npm -v # should print `10.7.0`
        相关命令
- fnm install #安装指定版本node
 - fnm install --lts #安装LTS版本
 - fnm uninstall #卸载指定版本
 - fnm uninstall #卸载指定别名node同时删除别名
 - fnm use <version|alias-name> #使用指定版本node
 - fnm alias #设置别名
 - fnm unalias #取消别名
 - fnm default #设置默认版本号