CentOS7 安装 nvm nrm pm2

8 篇文章 0 订阅

nvm 可以切换 nodejs 版本

使用git 方式安装nvm

方法:https://github.com/creationix/nvm#git-install
前提已安装git

  • cd ~/ - -切到主目录
  • git clone https://github.com/creationix/nvm.git .nvm - -克隆代码到文件夹 .nvm
  • cd ~/.nvm - -进入nvm代码目录
  • git checkout v0.33.11 - -切换到v0.33.11版本
  • source ~/.nvm/nvm.sh - -执行命令

如果需要安装最新版本:

[root@localhost .nvm]# nvm --version
0.33.11
[root@localhost .nvm]# git fetch -p
[root@localhost .nvm]# git rev-list --tags --max-count=1
258938ef66a2a49a4a400554a6dce890226ae34c
[root@localhost .nvm]# git describe --tags 258938ef66a2a49a4a400554a6dce890226ae34c
v0.35.3
[root@localhost .nvm]# git describe --abbrev=0 --tags
v0.35.3
[root@localhost .nvm]# git checkout $(git describe --tags `git rev-list --tags --max-count=1`)
Note: checking out 'v0.35.3'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD is now at 258938e... v0.35.3
[root@localhost .nvm]# source ~/.nvm/nvm.sh
[root@localhost .nvm]# nvm --version
0.35.3

解决下载缓慢问题,设置国内镜像

export NVM_NODEJS_ORG_MIRROR=https://npm.taobao.org/mirrors/node

将nvm添加到环境

echo "source ~/nvm/nvm.sh" >> ~/.bashrc

下面几个简单常用的命令:

查看远程版本

nvm ls-remote

安装版本

nvm install 10.9.0

切换版本

nvm use 10.9.0

查看所有版本

nvm ls

除了该方法,网上还有其他方法,但没尝试过:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
或者
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

安装nrm

已经安装完node之后,npm安装包下载都会缓慢,则需要切换其下载源,于是nrm来了
安装简单,直接:

npm i nrm -g

查看源

[root@localhost ~]# nrm ls
  npm -------- https://registry.npmjs.org/
  yarn ------- https://registry.yarnpkg.com/
  cnpm ------- http://r.cnpmjs.org/
* taobao ----- https://registry.npm.taobao.org/
  nj --------- https://registry.nodejitsu.com/
  npmMirror -- https://skimdb.npmjs.com/registry/
  edunpm ----- http://registry.enpmjs.org/

添加自己的私服

[root@localhost ~]# nrm add private http://10.10.2.14:8081/repository/

    add registry private  success
[root@localhost ~]# nrm use private

	Registry has been set to: http://10.10.2.14:8081/repository/

安装pm2

部署 node 应用,除了docker,pm2是一个不错的选择。
安装简单:

npm i pm2 -g
[root@localhost ~]# pm2 ls
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name               │ mode     │ ↺    │ status    │ cpu      │ memory   │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值