linux下使用npm install報EACCES的解決方法
前端專案需要進行CI/CD整合,CI伺服器是linux的,所以需要在伺服器上安裝npm環境,記錄一下安裝過程以及碰到的坑。安裝很簡單,直接下載官網的linux二進位制包,並將bin目錄設定在環境變數中就ok了,執行
[root@localhost dist]# npm -version
6.4.1
說明安裝成功了,接下來在執行專案的初始化(基於vue-cli)npm install時,卻反覆提示許可權不足
[root@localhost bocsh-vue-admin]# npm install
> nodent-runtime@3.2.1 install /home/gitlab-runner/builds/0444212d/0/7310754/bocsh-vue-admin/node_modules/nodent-runtime
> node build.js
fs.js:115
throw err;
^
Error: EACCES: permission denied, open '/home/gitlab-runner/builds/0444212d/0/7310754/bocsh-vue-admin/node_modules/nodent-runtime/dist/index.js'
at Object.openSync (fs.js:436:3)
at Object.writeFileSync (fs.js:1187:35)
at Object.<anonymous> (/home/gitlab-runner/builds/0444212d/0/7310754/bocsh-vue-admin/node_modules/nodent-runtime/build.js:5:4)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
at Function.Module._load (internal/modules/cjs/loader.js:529:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)
at startup (internal/bootstrap/node.js:285:19)
npm WARN ajv-errors@1.0.0 requires a peer of ajv@>=5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN ajv-keywords@2.1.1 requires a peer of ajv@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN eslint-config-standard@12.0.0-alpha.0 requires a peer of eslint@>=5.0.0-alpha.2 but none is installed. You must install peer dependencies yourself.
npm WARN bocsh-vue-admin@2.1.0 No repository field.
npm WARN bocsh-vue-admin@2.1.0 No license field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! nodent-runtime@3.2.1 install: `node build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the nodent-runtime@3.2.1 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
這裡百思不得其解,谷歌了半天,還是官網的一篇文章解決問題,就是更換npm的預設儲存庫(至於為什麼換了就好了,也不明白,我是root使用者啊。。),步驟如下:
- Back up your computer.
- On the command line, in your home directory, create a directory for global installations:
mkdir ~/.npm-global
- Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
- In your preferred text editor, open or create a ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH
- On the command line, update your system variables:
source ~/.profile
- To test your new configuration, install a package globally without using sudo:
npm install -g jshint
重新安裝package順利下載。
另外還有一個小問題是我們放在版本庫裡面的程式碼是沒有node_modules模組的,這樣的話CI伺服器每次檢出後都要執行npm install去下載所有的依賴modules,效率比較低,這邊的解決方案是先把node_modules目錄放在伺服器某個位置,在CI指令碼中增加
ln -s 源路徑 目標路徑
建立軟連線,這樣每次編譯的時候就不需要都執行npm install了。
總結:其實也沒啥好總結的,碰到問題多看官網多看英文文件(能谷歌最好),一般都比較靠譜。
官網文章連結
相關文章
- npm install 報錯解決NPM
- window環境下npm install node-sass報錯的解決方法NPM
- 使用npm install報錯-4048 operation not permitted解決NPMMIT
- npm install失敗解決方法NPM
- electron npm install 報錯解決方案NPM
- 關於npm install失敗的解決方法NPM
- 對於npm install失敗的解決方法:NPM
- 解決npm install 報錯,親測有效NPM
- npm install 安裝報錯解決方案NPM
- npm install安裝失敗解決方法NPM
- 解決npm install報錯Tried to download(403)NPM
- 關於npm install安裝報錯的解決辦法NPM
- Laravel Mix - 執行 NPM install 報錯解決辦法LaravelNPM
- npm install 失敗解決辦法NPM
- npm install 無響應解決方案NPM
- npm install失敗解決辦法NPM
- 使用npm install安裝webpack報錯ERRNPMWeb
- npm install報錯not found: python2的結局方法NPMPython
- npm install報錯, npm ERR! code MODULE_NOT_FOUNDNPM
- npm install報錯、失敗,出現network proxy問題解決方案NPM
- ionic3 ,win7下 npm install 報operation not permittedWin7NPMMIT
- ubuntu apt-get install xxx報錯無法下載的解決方法Ubuntuapt-get
- 解決:npm install ERR! Unexpected end of JSON inputNPMJSON
- Linux中npm出現npmlog找不到的解決方法LinuxNPM
- goland中npm無法使用的問題及解決方法GoLandNPM
- Windows 使用者執行 NPM run watch-poll 報錯的原因及解決方法WindowsNPM
- npm install 安裝外掛報錯NPM
- npm install realm --save失敗的問題與解決辦法NPM
- linux下easy_install的安裝與使用詳解Linux
- npm install -g 和npm install --save-dev的關係NPMdev
- 關於教程中 NPM 下載不穩定個人的解決方法NPM
- hive使用報錯解決方法Hive
- brew install gcc 卡住解決方法GC
- linux下SVN衝突的解決方法Linux
- npm install 安裝模組失敗了的簡單的解決辦法!!NPM
- Nodejs的npm安裝模組時候報錯:npm ERR! Error: CERT_UNTRUSTED的解決方法NodeJSNPMErrorRust
- npm publish 釋出一個 Angular 庫的時候報錯以及解決方法NPMAngular
- Linux下ODBC連線HGDB報Could not SQLConnect錯解決方法LinuxSQL