centos 使用 nvm 安装 nodejs (nvm安装时出错,git 版本太老)

安装 nvm

使用以下命令安装nvm ,结果出错

wget -qO- https://raw.githubusercontent.com/cnpm/nvm/master/install.sh | bash

如下:

➜  ~ wget -qO- https://raw.githubusercontent.com/cnpm/nvm/master/install.sh | bash
=> Downloading nvm from git to '/root/.nvm'
=> Initialized empty Git repository in /root/.nvm/.git/
remote: Counting objects: 3928, done.
remote: Total 3928 (delta 0), reused 0 (delta 0), pack-reused 3928
Receiving objects: 100% (3928/3928), 967.69 KiB | 210 KiB/s, done.
Resolving deltas: 100% (2299/2299), done.
error: pathspec 'v0.26.1' did not match any file(s) known to git.

他说错误,也看不出来什么错误,换了一种方式,使用下面的命令安装

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.29.0/install.sh | bash

这时也报错了,如下:

➜  ~ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.29.0/install.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  7731  100  7731    0     0   4345      0  0:00:01  0:00:01 --:--:--  5888
=> nvm is already installed in /root/.nvm, trying to update using git
=> error: pathspec 'v0.29.0' did not match any file(s) known to git.
Your version of git is out of date. Please update it!

=> Appending source string to /root/.zshrc
=> Close and reopen your terminal to start using nvm

不过他说 nvm 已经安装了 ,但是要更新 gitYour version of git is out of date. Please update it!

于是,看了以下 centos 系统里的 git 版本

➜  ~ git --version
git version 1.7.1

确实太老了,现在都 2.10 了,于是在 centos 6.7 上安装 git 的新版本了。

centos 系统中安装最新版 git ,请看我的另外一篇博文 《centos 6.7 安装 最新版 git》

nvm 安装完成后,可能要重启一下 shell 才有 nvm 这个命令。

重启 shell ,输入 nvm --version 可以查看当前 nvm 的版本,如下:

图片描述

安装 nodejs

查看都有哪些版本可以安装:

nvm ls-remote

可以看到当前最新版本是 v6.7.0 ,运行下面的命令来安装:

nvm install v4.6.0 #我安装的是 v4.6.0

查看安装的版本

node --version
➜  ~ nvm install v4.6.0
######################################################################## 100.0%
WARNING: checksums are currently disabled for node.js v4.0 and later
Now using node v4.6.0 (npm v2.15.9)
➜  ~ node --version
v4.6.0
➜  ~

查看一下当前已经安装的版本

nvm ls

切换版本

nvm use v4.6.0

设置默认版本

nvm alias default v4.6.0

nvm 使用很简单 ,详细内容请使用 nvm help 查看帮助。

图片描述