nodejs npm install全局安装和本地安装的区别
npm的包安装分为本地安装(local)、全局安装(global)两种,从敲的命令行来看,差别只是有没有-g而已,比如:
npminstallgrunt#本地安装 npminstall-ggrunt-cli#全局安装
下面分别解释。
1.npminstallxxx-g时,模块将被下载安装到【全局目录】中。
【全局目录】通过npmconfigsetprefix"目录路径"来设置。
通过npmconfiggetprefix来获取当前设置的目录。
2.npminstallxxx,则是将模块下载到当前命令行所在目录。
例如:
c:\123>npminstallxxx
将会安装到
c:\123\node_modules\xxx
这种方式显然是不好的,所以一般都会使用全局安装方式统一安装的一个目录中去,这样既方便管理、结构清晰还可以重复利用。