rainit2006 / JS-room

javascript knowledge
0 stars 0 forks source link

NPM #14

Open rainit2006 opened 6 years ago

rainit2006 commented 6 years ago

rainit2006 commented 6 years ago

グローバルにインストールしたnode moduleがnot foundになる時の対処 https://qiita.com/joe-re/items/12987cdeee506dea3889

.bash_profile にパスを設定してみる. vi ~/.bash_profile .bash_profile的所在路径: /home/ 下. 注意: Ubuntu 里是 ~/.profile .


Surprisingly, your npm installation has the global prefix in a folder called npm on your home directory, this means that any package installed with the -g flag will install on this folder.You can change this folder to any folder that is on the sudo safe path following these steps:

Graphical way:

  1. Open a File Manager (a.k.a Nautilus).
  2. Navigate to your home folder.
  3. Press Ctrl+H to show hidden files.
  4. Open a file called .npmrc with your favorite text editor. Find a line on that file with this content: prefix=/home/<your_username>/npm 5,Replace /home//npm by a safe path (such as /usr/local/bin). Once replaced it will look like this: prefix=/usr/local/bin Save the file. 6, Run againsudo npm install n -g

Terminal way: Run this command: sed -i.bak "s%^prefix=.*$%prefix=/usr/local/bin%" ~/.npmrc

rainit2006 commented 6 years ago

NPM升级到最新版 1.升级npm命令: sudo npm install npm -g

2.升级node.js命令步骤

sudo npm cache clean -f #-----先清除 npm cache
npm install -g n #-----安装n模块
sudo n stable #-----安装最新的node.js稳定版

https://laravel-china.org/articles/4060/upgrade-npm-and-nodejs-to-the-latest-version

rainit2006 commented 6 years ago

Proxy设定: $ npm -g config set proxy http://proxyserver:8080 $ npm -g config set https-proxy http://proxyserver:8080 $ npm -g config set registry http://registry.npmjs.org/

很多时候需要设定local配置才起作用,不知道为什么。 $ npm config set proxy http://proxyserver:8080 $ npm config set https-proxy http://proxyserver:8080 $ npm config set registry http://registry.npmjs.org/

查看设定内容: $ npm config list

npm-registry https://docs.npmjs.com/misc/registry The official public npm registry is at https://registry.npmjs.org/.

rainit2006 commented 6 years ago

Error遭遇经验: 很多是在Proxy环境下遭遇的。 发现我这里的机器上,设定Proxy时加上-g 不起作用。不加-g的时候反而管用。

或者将usr/local/bin/bin加入到PATH环境变量中,在~/.bashrc文件最后加入一行: export PATH=$PATH:/usr/local/bin/bin 之后再输入truffle,就会显示truffle版本和用法。