英文:
is installing node modules in your systems root folder that same as adding the -g flag to the module
问题
我通常使用终端在系统的根目录安装软件包,以便全局访问它们,但我也看到有人在安装软件包时使用了 -g 标志。
我想知道这两种方法之间的区别,以及哪种更适合实际使软件包全局可用。
英文:
I normally use my terminal and install packages in my systems root folder so I can access them globally, but I also see people use the -g flag when installing packages.
I would like to know the difference between the 2 and which one is better suited for actually making packages global.
答案1
得分: 1
以下是翻译好的部分:
如果你指的是npm全局文件夹/usr/lib/node_modules
,那么从技术上讲,不是。这 从技术上讲 与全局安装包没有区别。然而,这不是全局安装包的正确方法,可能会导致问题。使用npm -g
更容易更安全。
如果你指的是实际系统的根目录/
,这与全局安装包并不相同,绝对会在你的系统上造成问题。尽快停止这样做。
如果你指的是项目的根目录,那只是在本地安装包。
就你实际的问题而言,使用npm -g
,因为npm是设计用来以这种方式安装全局包的。这也可能比切换到你提到的任何文件夹并手动安装模块更容易。
英文:
What exactly do you mean by the root folder?
if you mean the npm global folder /usr/lib/node_modules
, then technically no. This is technically no different than globally installing the package. However, this is not the correct way to install the packages globally and could cause issues. It's easier and safer to just use npm -g
If you mean the actual system's root directory /
, this is not the same as globally installing a package and can DEFINATELY cause problems on your system. Stop doing this asap.
If you mean your project's root folder, then that's just installing the package locally.
In terms of your actual question, use npm -g
, as npm was designed to install global packages this way. It is also likely easier than cd-ing all the way to whichever folder you are mentioning and installing the module manually.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论