For some reason my npm is configured to install packages globally. I may have selected that option when I initially installed npm. However, I'm trying to change that configuration so npm installs locally. I googled and found this option:
npm config set global false
However, npm is still installing globally instead of locally. Am I missing a step or doing something incorrectly? Would you expect the command above to do what I need it to do?
npm installs packages locally by default. If you want to install a package globally use flag -g.
e.g. npm install my-package -g
Related
I have installed nodejs and then tried running the following command to install truffle suit and ganache as follows:
npm install -g truffle
npm install -g ganache
It got installed as follows:
Installing truffle and ganache
I also checked whether its present in the directories or not by running the command:
npm list -g
Yet when I run the command:
truffle -v
ganache -v
I get the error:
Error after installation
The package although it was installed globally, I couldn't access the package. I do have VS CODE and python 3.11 installed. Any suggestions to how can I use it globally?
I did try the following:
running npm config edit
changing the prefix to 'C:\Users\username\AppData\Roaming\npm'
adding that path to the system path variable
reinstalling the package with -g.
explicitly set the path by
npm config set prefix c:/Users//AppData/Roaming/npm
Change the permission of node global package without tampering with default file permission by
rather changing the directory itself along creating a new profile.
mkdir ~/.npm-global
npm config set prefix ~/.npm-global
set PATH=~/.npm-global/bin:$PATH
source ~/.profile
npm install -g <npm_packages>
But none of them worked
I am using nvm and via it I have set node v8.11.3 as my default. I installed the varint package globally using npm install -g --verbose varint, specifically to see where it is being installed. Post install on running npm list -g I can see it, but requiring it in the node repl fails. I am not sure as to what the issue is here. I am also not in a directory which has a package.json from before.
UPDATE:
which npm : ~/.nvm/versions/node/v8.11.3/bin/npm
which node : ~/.nvm/versions/node/v8.11.3/bin/node
I am trying to get global links working by default with npm v5. The same setup works on npm v4.
Consider the following:
npm config set global true
npm config set link true
The desired outcome should be that all packages installed by npm install are installed globally and all directories in node_modules are links to that global install.
In npm v4 this happens as expected. In npm v5 it does not. In npm v5, no packages are installed globally and the dependent packages are copied directly into node_modules as if the configs are being ignored entirely.
Can someone please explain this behavior and how to resolve if possible?
Following this question, NPM dependencies can be installed using:
$ npm install --ignore-scripts
Is there a way to mark that a dependency should be installed without running scripts in package.json?
This is because, when I run npm install --ignore-scripts, the dependency is added to package.json. As a result, other users will install the package while running scripts, however I want this certain package to never run scripts.
I could be wrong but I believe its: npm install -ignore-script package-name#version
I am new to npm, using package.json to define the dependencies. I am just curious where is those dependencies installed from?
First, npm checks your local machine for packages installed globally, or using the -g flag.
ie: if you used npm install -g moduleName
You can run npm list -g to figure out where that is on your machine.
Otherwise, npm goes to where you set the npm registry. By default this is npmjs.
If you want to see the default settings, run npm config list