archlinuxでnode.js環境を構築する

archlinuxでnode.jsを使うときのメモ

nvmのインストール

nvm(node version manager)はRubyのrvmやrbenvのように複数バージョンのnodeを
切り替えて使ったりできるツール
nodeは開発が発展途上で頻繁にバージョンアップがされるため、nvmの様なツールでバージョンを
管理すると開発がしやすくなると思う
githubのリポジトリにインストール方法があるので、それを参考にインストールする

[syguer@localhost]$ export PYTHON=python2
[syguer@localhost]$ curl https://raw.github.com/creationix/nvm/master/install.sh | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1391  100  1391    0     0    857      0  0:00:01  0:00:01 --:--:--   857
=> NVM is already installed in /home/syguer/.nvm, trying to update
=> Already up-to-date.

=> Profile not found. Tried /home/syguer/.bash_profile and /home/syguer/.profile
=> Run this script again after running the following:

\ttouch /home/syguer/.profile

-- OR --

=> Append the following line to the correct file yourself

\t[[ -s /home/syguer/.nvm/nvm.sh ]] && . /home/syguer/.nvm/nvm.sh  # This loads NVM

=> Close and reopen your terminal afterwards to start using NVM
[syguer@localhost]$

インストールが終わったらメッセージにあるように下記行を.bashrcなり.zshrcなりに追加する

[[ -s /home/syguer/.nvm/nvm.sh ]] && . /home/syguer/.nvm/nvm.sh  # This loads NVM

追加後にターミナルを再起動するか、下記コマンドを実施

[syguer@localhost]$ source .zshrc #bashの場合は.bashrcを指定

下記の様に表示されれば成功

[syguer@localhost]$ nvm

Node Version Manager

Usage:
    nvm help                    Show this message
    nvm install [-s] <version>  Download and install a <version>
    nvm uninstall <version>     Uninstall a version
    nvm use <version>           Modify PATH to use <version>
    nvm run <version> [<args>]  Run <version> with <args> as arguments
    nvm ls                      List installed versions
    nvm ls <version>            List versions matching a given description
    nvm ls-remote               List remote versions available for install
    nvm deactivate              Undo effects of NVM on current shell
    nvm alias [<pattern>]       Show all aliases beginning with <pattern>
    nvm alias <name> <version>  Set an alias named <name> pointing to <version>
    nvm unalias <name>          Deletes the alias named <name>
    nvm copy-packages <version> Install global NPM packages contained in <version> to current version

Example:
    nvm install v0.4.12         Install a specific version number
    nvm use 0.2                 Use the latest available 0.2.x release
    nvm run 0.4.12 myApp.js     Run myApp.js using node v0.4.12
    nvm alias default 0.4       Auto use the latest installed v0.4.x version

nvmでnodeをインストールする

下記のコマンドでインストールできるnodeのリストを取得できる

[syguer@localhost]$ nvm ls-remote                                [/home/syguer]

v0.1.14
v0.1.15
v0.1.16
v0.1.17
v0.1.18
v0.1.19
v0.1.20
v0.1.21
v0.1.22
v0.1.23
v0.1.24
v0.1.25
v0.1.26
v0.1.27
v0.1.28
v0.1.29
v0.1.30
v0.1.31
v0.1.32
v0.1.33
v0.1.90
v0.1.91
v0.1.92
v0.1.93
v0.1.94
v0.1.95
v0.1.96
v0.1.97
v0.1.98
v0.1.99
v0.1.100
v0.1.101
v0.1.102
v0.1.103
v0.1.104
v0.2.0
--------------------省略----------------------

この中から下記コマンドで好きなバージョンを指定してインストール
ここではeXcaleで使える最新バージョンであるv0.10.9を指定

[syguer@localhost]$ nvm install v0.10.9                          
######################################################################## 100.0%
Now using node v0.10.9

nvm lsコマンドでインストール済みのnodeと現在のnodeを確認できる
変更をしたい場合はnvm useコマンドで変更できる

[syguer@localhost]$ nvm ls                                       [/home/syguer]

   v0.10.9
current: 	v0.10.9
[syguer@localhost]$
[syguer@localhost]$ nvm install v0.10.8                          
######################################################################## 100.0%
Now using node v0.10.8
[syguer@localhost]$                                              
[syguer@localhost]$                                              
[syguer@localhost]$ nvm ls                                       

v0.10.8
v0.10.9
current: 	v0.10.8
[syguer@localhost]$                                              
[syguer@localhost]$ nvm use v0.10.9                              
Now using node v0.10.9
[syguer@localhost]$                                              
[syguer@localhost]$                                              
[syguer@localhost]$ nvm ls                                       

v0.10.8
v0.10.9
current: 	v0.10.9
[syguer@localhost]$ 

これで構築完了