LoginSignup
18
11

More than 5 years have passed since last update.

Visual Studio Codeのbashでnpmが使えなかった問題

Posted at

Visual Studio Codeのターミナルをcmdからbashに変更した際にnpmコマンドが使えなくなってしまっていた問題の原因とその解決方法のメモです。

問題

$ npm

を実行すると

: not foundram Files/nodejs/npm: 3: /mnt/c/Program Files/nodejs/npm:
: not foundram Files/nodejs/npm: 5: /mnt/c/Program Files/nodejs/npm:
/mnt/c/Program Files/nodejs/npm: 6: /mnt/c/Program Files/nodejs/npm: Syntax error: word unexpected (expecting "in")

のようなエラーが出る。

npm command not found みたいなメッセージが出ないのでちょっと悩んだ。

原因

原因自体はスゴイ単純で、自分の思いすごしに起因したものでした。

というのも、Windowsに既にnodeもnpmも入ってるんだからbashにしたところで関係ないっしょ、と思っていたのです。

実際はbash(が動いている仮想Ubuntu?)に一から環境構築してやらなきゃいけないようです。

解決方法

bash上で以下を行う

# パッケージのアップデート
$ sudo apt-get -y update
$ sudo apt-get -y upgrade
$ sudo apt-get -y dist-upgrade
$ sudo apt-get autoremove

# nodejsをインストール
$ curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -  //もしかするとURLは適宜選択しなければならないかも
$ sudo apt-get install -y nodejs

#パスを変更
$ vi ~/.profile
# 最後尾にPATH="$HOME/bin:$HOME/.local/bin:$PATH" を追記
$ source ~/.profile
18
11
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
18
11