-bash: http-server: command not found

MacOS 終端執行http-server命令,開啓本地服務器時,遇到以下報錯信息

coolpeng:~ littlelittlepeng$ http-server
-bash: http-server: command not found

報錯原因

npm全局安裝路徑沒有被加入到bash的$PATH環境變量中

解決辦法

  1. 執行以下命令,查看http-server的安裝路徑,步驟3中需要用到
npm install http-server -g

獲取安裝路徑

  1. 終端輸入以下命令,打開bash環境編輯頁面
open .bash_profile

bash_profile02

  1. 加入以下環境變量,注意bin: 後邊的路徑爲步驟1中獲取到的安裝路徑
export PATH=$PATH:$M2_HOME/bin:/usr/local/Cellar/node/9.4.0/lib/node_modules/http-server/bin/

bash_profile03

  1. 保存bash_profile文件,然後在終端中輸入source .bash_profile命令,即可生效。
  2. 終端執行以下命令,啓動本地服務器成功
http-server

成功開啓本地服務器

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章