5
3

More than 3 years have passed since last update.

bashでnpmのpathを通す

Posted at

はじめに

ターミナルでngコマンドvueコマンドなどを実行する際に、command not foundと表示された時の対処です。

動作環境

MacとUbuntu(WSL環境)でのbashで動作確認しています。
bashが動作する環境なら同じ設定で動作すると思います。

一時的にnpmのpathを通す

bashで下記のコマンドの実行します。

export PATH=$PATH:`npm bin -g`

pathを通す

ホームディレクトリに移動し、.profileを編集します。

cd
sudo vim .profile

.profileにpathを追記します。

.profile
export PATH=$PATH:`npm bin -g`

再起動します。

sudo reboot

上記の実行でbashにエラーが表示される場合

bashの起動時に(not in PATH env variable)と表示される場合でも、ngコマンドvueコマンドを実行することが可能になっていると思いますが、エラーの表示を無くしたい場合は下記の手順を実行します。

/etc/environmentを編集します。

cd /etc
sudo vim environment

environmentにpathを追記します。

environment
export PATH=$PATH:`npm bin -g`

再起動します。

sudo reboot
5
3
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
5
3