LoginSignup
31
18

More than 5 years have passed since last update.

Nodebrewを使ってNode.jsを超高速にインストールする方法

Last updated at Posted at 2016-08-12

Node.jsのインストールって、コンパイルに時間がかかりますよね。
その度に、イライラしている方もいるのではないでしょうか。
今回は、Node.jsを超高速でインストールできる方法を紹介します。

この方法を使うと、インストール時間が1秒以下になります(マシンスペック&ネットワークに依存しますが・・・)

検証環境

検証環境はVagrantを使っています。
OSとスペックは以下の通りです。

centos
# OS
$ cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)

# memory
$ cat /proc/meminfo | grep Total
MemTotal:        1884064 kB

# core数
$ cat /proc/cpuinfo | grep "processor" | wc -l
2

事前準備

nodebrewをインストールする。

$ curl -L git.io/nodebrew | perl - setup
$ echo 'export PATH=$HOME/.nodebrew/current/bin:$PATH' >> ~/.bashrc
$ source ~/.bashrc

インストール方法

今回は3種類のインストール方法を比較します。

  • 通常のインストール(コンパイルあり)
  • バイナリファイルからインストール(コンパイルなし)
  • バイナリファイルのインストールを並列化(コンパイルなし)

通常のインストールではコンパイルを行い、install-binaryを使うとコンパイルを行いません。

3種類のインストール方法
# 通常のインストール
$ nodebrew install <version>

# install-binaryを使ってインストール
$ nodebrew install-binary <version>

では、実際にどのくらい時間差が出るか比較をしてみましょう。

比較結果

インストール方法 インストール時間
nodebrew install v4.4.3 15分6秒
nodebrew install-binary v4.4.3 46秒

※ 上記のコマンドが実行完了するまでの時間です。(nodebrew use <version>の時間は除いています)

インストールが完了したら・・・

忘れずにnodeのバージョンを指定しましょう。

nodeのバージョンを指定する
$ nodebrew use v4.4.3

これで超高速で、nodeを使えるようになりました!

まとめ

binary fileを使うだけで実行時間がが15分の1に。

これは、使わないわけにいかないですね・・・!(速すぎて驚きが隠せません)

31
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
31
18