LoginSignup
0
0

More than 3 years have passed since last update.

WSLでのnode管理をnからnodebrewに切り替え

Posted at

はじめに

Windows10 ProにWSLを入れて開発をしています。
以前はnを使ってnodeのバージョン管理をしていたのですが、
ある問題にぶつかりnodebrewに切り替えました。
そのときのメモです。

問題とは、Windows側にインストールしたRunJSで、
npm packageのインストールができないことでした。
nodebrewに切り替えたら問題なくインストールできるようになりました。

環境

  • Windows 10 Pro
  • WSL
    • version 2
    • Ubuntu 20.04 LTS

方法

n のアンインストール

こちらの記事を参考にしました。

$ sudo n uninstall
$ sudo rm -rf /usr/local/n

nodebrewのインストール

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

.bash_profileに以下を環境変数の設定を記述

export PATH="$HOME/.nodebrew/current/bin:$PATH"

環境変数を適用

source .bash_profile

nodeのインストール

nodebrewでnodeをインストールします。
今回は最新の安定板をインストールしました。

$ nodebrew install-binary stable
$ nodebrew use stable
use v14.16.0

# [補足]インストール可能なバージョンの確認
$ nodebrew ls-all

インストールされたnodeの確認

$ which node
/home/mypath/.nodebrew/current/bin/node
$ which npm
/home/mypath/.nodebrew/current/bin/npm
$ node -v
v14.16.0
$ npm -v
-bash: /mnt/c/Program Files/nodejs/npm: /bin/sh^M: bad interpreter: No such file or directory

npmのパスを誤って認識しているらしい。

トラブルシューティング

.bash_profileのパスの設定を以下のように変更して解決

export PATH="$HOME/bin:$HOME/.local/bin:$HOME/.nodebrew/current/bin:$PATH"

これでWindows側でインストールしたRunJSでもnpm packageをインストールできるようになりました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0