Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 9130

Mac環境にNode.jsをインストールする

$
0
0

はじめに

Mac環境にNode.jsをインストールする方法としていくつかの方法があります。ここではバージョン管理を行うためにnodenvを利用した方法についてまとめます。

インストール

Node.jsをインストールするためには、以下をインストールする必要があります。

  1. Homebrewをインストール
  2. nodenvをインストール

Homebrewのインストール

Homebrewをインストールします。Homebrewに書かれているインストールコマンドを実行します。

$ /usr/bin/ruby -e"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

brew doctorを実行して、インストール確認を行います。

$ brew doctor
Your system is ready to brew.

これでHomebrewのインストールは完了です。

nodenvのインストール

Homebrewからnodenvをインストールします。

$ brew install nodenv

~/.bash_profile、または~/.zprofileにeval "$(nodenv init -)"を追加します。
nodenv initを実行することで、どこに何を追加したらよいのかを確認することができます。

$ nodenv init
# Load nodenv automatically by appending# the following to ~/.bash_profile:eval"$(nodenv init -)"

nodenv-doctorを実行してインストール確認します。

$ curl -fsSL https://github.com/nodenv/nodenv-installer/raw/master/bin/nodenv-doctor | bash
Checking for`nodenv' in PATH: /usr/local/bin/nodenv
Checking for nodenv shims in PATH: OK
Checking `nodenv install' support: /usr/local/bin/nodenv-install (node-build 4.9.32)
Counting installed Node versions: none
  There aren't any Node versions installed under `/Users/*****/.nodenv/versions'.
  You can install Node versions like so: nodenv install 2.2.4
Auditing installed plugins: OK

これでnodenvのインストールは完了です。

Node.jsのインストール

nodenvからNode.jsをインストールします。
インストール可能なバージョンを確認します。

$ nodenv install-list
0.1.14
0.1.15
0.1.16

# 省略...

nightly
node-dev
rc
v8-canary

バージョンを指定してNode.jsをインストールします。(ここでは14.16.0をインストール)

$ nodenv install 14.16.0
Downloading node-v14.16.0-darwin-x64.tar.gz...
-> https://nodejs.org/dist/v14.16.0/node-v14.16.0-darwin-x64.tar.gz
Installing node-v14.16.0-darwin-x64...
Installed node-v14.16.0-darwin-x64 to /Users/*****/.nodenv/versions/14.16.0

インストールした後は、nodenv rehashを実行しておきます。

$ nodenv rehash

これでNode.jsのインストールは完了です。

使用するNode.jsの指定

nodenv globalを実行して使用するNode.jsのバージョンを指定します。(ここでは14.16.0を指定)

$ nodenv global 14.16.0 

また、プロジェクト別(ディレクトリ別)に指定することもできます。

$ nodenv local 14.16.0 

アンインストール

Node.jsのアンインストール

特定のバージョンをアンインストールしたい場合はnodenv uninstallを実行します。(ここでは14.16.0をアンインストール)

$ nodenv uninstall 14.16.0

Viewing all articles
Browse latest Browse all 9130

Trending Articles