nodeとnpmのインストール手順を紹介します。
実行ログも多少つけました。
<スポンサードリンク>
node,npmインストール手順
1,nodebrewをインストール
% brew install nodebrew
※長いので省略していますが、成功すると下記のようなインストールログででます。
==> Downloading https://github.com/hokaccha/nodebrew/archive/v1.0.0.tar.gz ==> Downloading from https://codeload.github.com/hokaccha/nodebrew/tar.gz/v1.0.0 ######################################################################## 100.0% ==> Caveats You need to manually run setup_dirs to create directories required by nodebrew: /usr/local/opt/nodebrew/bin/nodebrew setup_dirs Add path: export PATH=$HOME/.nodebrew/current/bin:$PATH To use Homebrew's directories rather than ~/.nodebrew add to your profile: export NODEBREW_ROOT=/usr/local/var/nodebrew Bash completion has been installed to: /usr/local/etc/bash_completion.d zsh completions have been installed to: /usr/local/share/zsh/site-functions ==> Summary 🍺 /usr/local/Cellar/nodebrew/1.0.0: 8 files, 38.5KB, built in 8 seconds
2. nodebrewのバージョンを確認
% nodebrew version 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> Example: # install nodebrew install v8.9.4 # use a specific version number nodebrew use v8.9.4
2.最新のnodeをインストール
% nodebrew install-binary latest
なんか下記のようなエラーが発生したので、必要そうなディレクトリを作成
※よくでるエラーみたいです。早く修正してほしいですね、、、
% nodebrew install-binary latest Fetching: https://nodejs.org/dist/v10.0.0/node-v10.0.0-darwin-x64.tar.gz Warning: Failed to create the file Warning: /Users/shimadarei/.nodebrew/src/v10.0.0/node-v10.0.0-darwin-x64.tar.gz Warning: : No such file or directory curl: (23) Failed writing body (0 != 847) download failed: https://nodejs.org/dist/v10.0.0/node-v10.0.0-darwin-x64.tar.gz
% mkdir -p ~/.nodebrew/src
3.インストールされたnodeのバージョンを確認
% nodebrew list v10.0.0 current: none
4.インストール直後は、current:noneになっているので、使用するバージョンを有効化しておきます。
% nodebrew use 10.0.0 use v10.0.0
5.nodeコマンドへパスを通して、ターミナルを再起動します。
echo 'export PATH=$PATH:/Users/xxxxx/.nodebrew/current/bin' >> ~/.bashrc
以上でnodeとnpmのinstallは完了です。