安裝 cnpm 後 cnpm -v 卻找不到、配置時候又遇到這個找不到、同理邏輯和上篇yarn 一樣處理。
首先确認一下 npm 下載下傳包路徑:
一。檢視 npm 的 prefix 和 cache 設定資訊
1|npm config get prefix
2|npm config get cache
二。設定下載下傳路徑和緩存路徑
1|npm config set prefix “usr/example”
2|npm config set cache “usr/example“
三。檢視 npm 配置下資訊
1|npm config list
然後配置 cnpm 的環境變量
環境變量 :記錄電腦各種内容的位置
如何設定 : export PATH=path1/example:$PATH
一。建立并打開 .bash_profile 檔案
1|cd ~
2|touch .bash_profile
3|open .bash_profile
二。添加 cnpm 的路徑 儲存 退出,設定全局路徑
1|export PATH=$PATH:/Users/你的使用者/example/bin
2|source .bash_profile
通常 node 和 npm 指令都安裝在 usr/local/bin 路徑下,如果不将這個路徑添加到 path 變量裡,通
過 npm 安裝的的各種包都會 not found; 是以要記得操作:
export PATH="$PATH:/usr/local/bin"
解決前如下:
解決後如下圖: