Ubuntu18.04にnodebrew使ってnode.jsをインストールした

Angularを使ってみるということでまずはNode.jsをインストールしました。

Node.js

node.js の環境管理ツール nodebrewをインストール

node.js の環境管理ツールについて

他の環境管理ツールはnvm, nave , n , nodeenvなどがあるみたいです。

Jxckさんがnodebrewを絶賛してます。 jxck.hatenablog.com

nvmをインストールしてた方はアンインストールする必要があります。 chaika.hatenablog.com

nodebrewをインストール

以下のREADMEの手順でインストールしていきます。 github.com

curl -L git.io/nodebrew | perl - setupをしたのだが、curlをインストールしてなかったのでまずはそちらをインストール。

curlとはまざまなプロトコルに対応したデータを転送するためのコマンドです。

 「wget」コマンドのように、“HTMLを解析して、リンク先もダウンロードする”ような機能はありませんが、URLに連番を指定するといった使い方ができます。

www.atmarkit.co.jp

POSTDの記事が分かりやすかったです。 postd.cc

機能の比較表。 curl - Comparison Table

Install and Learn to Use Curl on Ubuntu 18.04 – Linux Hint 上記のブログに従ってUpdateして、その後にcurlを入れました。

sudo apt-get update

sudo apt-get install curl
curl --version

curl 7.58.0 (x86_64-pc-linux-gnu) libcurl/7.58.0 OpenSSL/1.1.0g zlib/1.2.11 libidn2/2.0.4 libpsl/0.19.1 (+libidn2/2.0.4) nghttp2/1.30.0 librtmp/2.3

インストールできたみたい。

nodebrewをインストール。

curl -L git.io/nodebrew | perl - setup

.bash_profileに環境変数のパスを追加

echo 'export PATH=$HOME/.nodebrew/current/bin:$PATH' >> ~/.bash_profile

.bash_profileを再読込み

source ~/.bash_profile

nodebrewがインストールされたか確認

nodebrew help

インストールされてたら以下のような感じになる。

nodebrew 1.0.0

Usage:
    nodebrew help                         Show this message
    nodebrew install <version>            Download and install <version> (from binary)
    nodebrew compile <version>            Download and install <version> (from source)
    nodebrew install-binary <version>     Alias of `install` (For backword compatibility)
    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

node.jsのインストール

nodebrewで最新版のNode.jsをインストール

nodebrew install-binary stable

nodebrew install-binaryを使うと、通常と違いコンパイルしないので速くインストールできます。 qiita.com

nodebrewでインストールされたNode.jsのバージョンを確認

nodebrew ls

// 以下が表示された
v10.7.0

current: none

nodebrewで利用するNode.jsのバージョンを指定

nodebrew use v10.7.0

v10.7.0しかなかったのでこのバージョンにしました。7/29現在の最新版です。

リリース一覧 | Node.js

Node.jsのバージョンを確認

node -v

v10.7.0

とりあえずインストール完了

無事インストールできたみたいです。 よかったです。