本文以Debian或者Ubuntu系统为例,CentOS的话,只需把apt
换成yum
即可。
1. 更新相关系统包
在安装任何软件之前,通过apt在终端中运行以下命令来确保您的系统是最新的
sudo apt update
sudo apt upgrade
2. 通用运行下面的命令来下载并运行 NVM 安装脚本
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
如果报找不到curl
命令,则使用apt install curl
进行安装
3. 在.bashrc
文件中添加环境变量
安装成功后,NVM会提示让你配置环境变量,如下:
root@junyang:~# curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 15916 100 15916 0 0 82895 0 --:--:-- --:--:-- --:--:-- 83329
=> Downloading nvm from git to '/root/.nvm'
=> Initialized empty Git repository in /root/.nvm/.git/
=> Compressing and cleaning up git repository
=> nvm source string already in /root/.bashrc
=> bash_completion source string already in /root/.bashrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
编辑root目录下的.bashrc
文件,把下面内容添加到文件中
vim ~/.bashrc
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
4. 重载.bashrc
配置文件
source ~/.bashrc
5. 查看NVM版本
nvm --version
评论区