ポリミーイズム

PHPを勉強する若輩者(おっさん)。専門用語の意味はわりかし覚えていません。macOS Sierra 10.12.6

Node.js, npm, nodebrew

背景

npmのバージョンもnodeのバージョンも低かったので、再インストール
Macなので、Homebrewを使用し行う。
また、nodebrewを使用し、今後nodeの管理を行う。

参考

手順

現時点でのnode,npmのバージョンを確認

node --version  
npm --version  

└ 最初に叩いた時には、npmは存在したのだが、その後npmアップデート(下記コマンド)をしようとしたら消滅。

npm update -g npm

参考

nodebrewをインストール

npmは消えたが、nodeはversion0.10.33とかいうベータのようなバージョンが入っていたので、nodebrewをそのままインストールすることで、依存関係の解決を行なってくれると一縷の望みを抱き続行。

  • 実行コマンド
brew install nodebrew
  • 結果
==> Deleted Formulae
abi-compliance-checker     kes                        rexster
elixirscript               mapnik@2                   rexster-console
gh                         node@0.10                  szl
go-gui                     node@0.12                  tcpurify
jpeg@9                     phantomjs@1.92
kafka@0.80                 phantomjs@1.98

/usr/local/Homebrew/Library/Homebrew/brew.rb:12:in `<main>': Homebrew must be run under Ruby 2.3! (RuntimeError)

└ おいおい、エラー出てんぞ。Rubyのバージョンが高いんか?

Rubyバージョン確認

ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin13]

rbenv(Rubyのバージョン管理)より試しに2.2.2を入れる

rbenv install -l    # インストール可能なリストを表示
rbenv install 2.2.2 

Rubyバージョンを切り替える

rbenv global 2.2.2
rbenv versions

バージョンを切り替えた後にnodebrewをインストール

brew install nodebrew

└ 成功。

nodebrewにパスを通す

echo 'export PATH=$PATH:/Users/uronoro/.nodebrew/current/bin' >> ~/.bashrc

- /.bash_profileに下記追加
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

node.jsのバージョン確認

nodebrew ls-remote    # リモートで管理されているNode.jsのバージョンを調べる

node.js最新バージョンをインストール

nodebrew install-binary latest

└ エラー出てんぞ。(今期2度目)

Fetching: https://nodejs.org/dist/v8.6.0/node-v8.6.0-darwin-x64.tar.gz
Warning: Failed to create the file 
Warning: /Users/uronoro/.nodebrew/src/v8.6.0/node-v8.6.0-darwin-x64.tar.gz: No 
Warning: such file or directory

curl: (23) Failed writing body (0 != 941)
download failed: https://nodejs.org/dist/v8.6.0/node-v8.6.0-darwin-x64.tar.gz

ディレクトリないよーって言われてる気がしたので、ディレクトリを作成

ディレクトリを作成

mkdir -p ~/.nodebrew/src

npmがないままやからインストール

curl -L https://www.npmjs.org/install.sh | sh

nodeのバージョン足りんぞと怒られる(今期3度目)

ERROR: npm is known not to run on Node.js v0.10.33
You'll need to upgrade to a newer version in order to use this
version of npm. Supported versions are 4, 6, 7, 8. You can find the
latest version at https://nodejs.org/
ERROR: npm is known not to run on Node.js v0.10.33
You'll need to upgrade to a newer version in order to use this
version of npm. Supported versions are 4, 6, 7, 8. You can find the
latest version at https://nodejs.org/
It failed

nodeの使用バージョンとnodebrewでインストールしたバージョンが一致せんぞ。
元々いれてしまっていたNode.jsのバージョン(0.10.33)が邪魔しているのかな。

元々いれていた古いバージョンが原因?

この線で考えていったときに、ずっと表示されていたnode v0.10が原因かな、とnodeごと削除。ターミナル再起動。
nodeとnpmのバージョン確認できた。okかな?今後はnodebrewで管理すること。

既存のnodeを削除

lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom \
| while read i; do
  sudo rm /usr/local/${i}
done
sudo rm -rf /usr/local/lib/node \
     /usr/local/lib/node_modules \
     /var/db/receipts/org.nodejs.*

参考

http://d.sonicjam.co.jp/post/52541343939

反省

わからずコピペすることほど怖いものはないからね。今回はうまくいったからええけど次回からはコマンドも調べること。