nodeのuninstallとnodebrewのインストール
スポンサーリンク
nodeとnpmを再インストールする
久々にnodeをさわろうとして、npmとうつと、
module.js:340 throw err; ^ Error: Cannot find module './lib/optional' at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Module.require (module.js:362:17) at require (module.js:378:17) at Object. (/usr/local/lib/node_modules/npm/node_modules/request/index.js:15:16) at Module._compile (module.js:449:26) at Object.Module._extensions..js (module.js:467:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Module.require (module.js:362:17)
とこんなのが出るようになった。がーん、まともに動かない。
というわけでnodeとnpmを再インストールする。
sudo npm uninstall npm
もできないので、正攻法ではない方法を使わせてもらう。
Instructions on how to fix npm if you've installed Node through Homebrew on Mac OS X or Linuxbrew
rm -rf /usr/local/lib/node_modules brew uninstall node brew install node --without-npm echo prefix=~/.node >> ~/.npmrc curl -L https://www.npmjs.com/install.sh | sh
これを見てnpmをreinstallした。サイトにのっているコマンドをコピペでOK。 また、PATHにnodeのパスを追加するのも忘れないように。 結局nodeもインストールしているが、nodeなしでnpmだけインストールできるか不明だったのでついでにインストールしちゃった。
export PATH="$HOME/.node/bin:$PATH"
node.jsのバージョン管理をするためにnodebrewもインストールする。
node.jsのversionを管理するためにnodebrewを利用する - Qiita
結局さっきnodeインストールしたけど、nodeだけuninstall。
uninstall用のスクリプトを叩く。
curl -o uninstall-node.sh https://gist.githubusercontent.com/nicerobot/2697848/raw/uninstall-node.sh chmod u+x uninstall-node.sh ./uninstall-node.sh rm uninstall-node.sh sudo rm -rf /usr/local/include/node sudo rm -rf /usr/local/lib/dtrace rm -rf ~/.node-gyp rm -rf ~/.npm rm -rf ~/.sourcemint
nodebrewのインストール
curl -L git.io/nodebrew | perl - setup
nodeのインストール。最新版をとりあえずインストールする。install-binaryだと速い。
nodebrew install-binary v0.12.7
以下コマンドで使用開始する。
nodebrew use v0.12.7