51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

Linux(CentOS、Ubuntu、Debian)安装NVM

本文以Debian或者Ubuntu系统为例,CentOS的话,只需把apt换成yum即可。

  1. 更新相关系统包 {#1.-%E6%9B%B4%E6%96%B0%E7%9B%B8%E5%85%B3%E7%B3%BB%E7%BB%9F%E5%8C%85} ================================================================================

在安装任何软件之前,通过apt在终端中运行以下命令来确保您的系统是最新的

sudo apt update
sudo apt upgrade
  1. 通用运行下面的命令来下载并运行 NVM 安装脚本 {#2.-%E9%80%9A%E7%94%A8%E8%BF%90%E8%A1%8C%E4%B8%8B%E9%9D%A2%E7%9A%84%E5%91%BD%E4%BB%A4%E6%9D%A5%E4%B8%8B%E8%BD%BD%E5%B9%B6%E8%BF%90%E8%A1%8C-nvm-%E5%AE%89%E8%A3%85%E8%84%9A%E6%9C%AC} ==================================================================================================================================================================================================================
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash

如果报找不到curl命令,则使用apt install curl进行安装

  1. .bashrc文件中添加环境变量 {#3.-%E5%9C%A8.bashrc%E6%96%87%E4%BB%B6%E4%B8%AD%E6%B7%BB%E5%8A%A0%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F} ==============================================================================================================================

安装成功后,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
  1. 重载.bashrc配置文件 {#4.-%E9%87%8D%E8%BD%BD.bashrc%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6} ======================================================================================
source ~/.bashrc
  1. 查看NVM版本 {#5.-%E6%9F%A5%E7%9C%8Bnvm%E7%89%88%E6%9C%AC} ========================================================
nvm --version  
  1. NVM常用命令 {#6.-nvm%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4} ========================================================

参考文章:https://blog.fjy.zone/archives/nvm-command

赞(3)
未经允许不得转载:工具盒子 » Linux(CentOS、Ubuntu、Debian)安装NVM