0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

個人的備忘録:json-server をインストールしたのに "command not found" と出たときの対応メモ

Posted at

はじめに

json-server をグローバルインストールしても、コマンドが認識されず command not found と表示されることがあります。

個人の備忘録程度の走り書きとなっておりますが、温かい目で見守っていただければ幸いです。

以下は実際に遭遇したケースとその解決方法の記録です。

発生した事象

npm install -g json-server

コマンド実行後:

changed 45 packages in 384ms

14 packages are looking for funding
  run `npm fund` for details

しかし、次のように実行すると:

json-server --watch db.json --port 3000
zsh: command not found: json-server

初期確認コマンド

which json-server  # → json-server not found

グローバルインストール先の確認

npm list -g --depth=0

出力:

/Users/xxx/.npm-global/lib
└── json-server@1.0.0-beta.3

解決方法

  1. 実行バイナリの場所を確認:
ls /Users/xxx/.npm-global/bin/json-server

ファイルが存在すれば OK。

  1. .zshrc にパスを追加:
echo 'export PATH=$HOME/.npm-global/bin:$PATH' >> ~/.zshrc
source ~/.zshrc
  1. 再度確認:
which json-server

パスが表示されるようになれば成功!

  1. サーバー起動:
json-server --watch db.json --port 3000

まとめ

  • npm install -g しても $PATH が通っていないと実行できない
  • .npm-global/bin を PATH に追加するのがポイント

npm や zsh を使う際によくあるミスなので、備忘録として残しておきます...!

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?