CentOS7にnodebrewを使ってnode.jsをインストールする

CentOS7にnode.jsをインストールしてみたいと思います。

nodebrewを使ってインストール

Node.jsのバージョン管理ツールがあるらしく、nodebrewというみたいです。これを使ってインストールしたいと思います。

nodebrewをインストール

[root@]# curl -L git.io/nodebrew | perl - setup
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
100 24340 100 24340 0 0 10698 0 0:00:02 0:00:02 --:--:-- 99346
Fetching nodebrew...
Installed nodebrew in $HOME/.nodebrew
========================================
Export a path to nodebrew:
export PATH=$HOME/.nodebrew/current/bin:$PATH
========================================

環境変数の設定

.bash_profileに以下を追加します。

[root@]# vim ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
export PATH=$HOME/.nodebrew/current/bin:$PATH #追加

追加しました。 .bash_profileを読み込み直します。

source ~/.bash_profile
nodebrew help
nodebrew 0.9.6
Usage:
nodebrew help Show this message
nodebrew install <version> Download and install <version> (compile from source)
nodebrew install-binary <version> Download and install <version> (binary file)
nodebrew uninstall <version> Uninstall <version>
nodebrew use <version> Use <version>
nodebrew list List installed versions
nodebrew ls Alias for `list`
nodebrew ls-remote List remote versions
nodebrew ls-all List remote and installed versions
nodebrew alias <key> <value> Set alias
nodebrew unalias <key> Remove alias
nodebrew clean <version> | all Remove source file
nodebrew selfupdate Update nodebrew
nodebrew migrate-package <version> Install global NPM packages contained in <version> to current version
nodebrew exec <version> -- <command> Execute <command> using specified <version>
Example:
# install from binary
nodebrew install-binary v0.10.22
# use a specific version number
nodebrew use v0.10.22
# io.js
nodebrew install-binary io@v1.0.0
nodebrew use io@v1.0.0

バージョン確認します

[root@]# nodebrew ls-remote

バージョンを指定してインストール

[root@]# nodebrew install-binary <version>

安定版のインストール

[root@]# nodebrew install-binary stable

インストールしたNode.jsのバージョン確認

[root@]# nodebrew list
v7.0.0
current: none

Node.jsのバージョンを指定

[root@]# nodebrew use <version>

Node.jsの安定版を指定

[root@]# nodebrew use stable

Node.jsとnpmのバージョン確認

[root@]# node -v
v7.0.0
[root@]# npm -v
3.10.8

Nodo.jsのインストールの成功です