I work in a big organisation as UX designer. I have basic programming knowledge. I've been trying for ways to install node / npm on macOS without admin rights with no luck.
I've tried all the methods described here
https://gist.github.com/isaacs/579814
but all of them require using sudo or make which I cannot use
I've also downloaded the installer from nodejs.org and, unpack the file with pkgutil but when I run tar on the payloads they are copied to usr/local/bin/includes/node then I try to change the path in the host file but I need admin password to save.
I thought that this would be as easy as doing it on a Windows machine but it's not.
I am trying to install continues integration server. This server will pull data from GIT and it will try to build the application. Since I am using windows 2012 server, multiple users can trigger the build. For this purpose, I want to ensure all the node packages I install as admin are available to all users.
How can I:
Install node packages globally that are available to all users.
I want to use a locally hosted node registry. I don't want to use node registry.
After the installing the packages, how can I validate if all users can access the packages?
Had the same issue. Needed the CI build agent to run a global package on the CLI. Saw this post in a new feature request for system-wide npm -g for Windows.
In short:
Open an administrator level command prompt
Note the current global prefix: npm prefix -g
Set the global prefix to the CI user: npm config set prefix <C:\Users\CI_USER\AppData\Roaming\npm>
Install the needed packages: npm i -g PKG
Restore the prefix to the previous value.
For the 'Network Service' account use the folder:
C:\Windows\ServiceProfiles\NetworkService\AppData\Roaming\npm
You can add a global environment variable NODE_PATH to set the package require search path. You may see here for more.
https://gist.github.com/branneman/8048520#4-the-environment
I'm setting up a developer environment on OSX and want to use homebrew to manage installs. I am going on the premise that my regular dev account should not be an admin account and then I have setup an additional admin account for the purposes of performing homebrew installs. I think this is the safest way to use homebrew and to avoid sudo as per the recommendation.
I am now having problems installing node/npm and am wary and hesitant of the changes I need to make to fix it.
(for the purposes of this question, dev account=kramer, admin account=admin).
I installed homebrew using as my admin account.
If I ls my /usr/local/Cellar directory I see:
drwxr-xr-x 2 Kramer admin 68 26 Jul 12:47 /usr/local/Cellar
which shows that only the owner Kramer has write permissions to it.
Then if I ls my /usr/local directory is see:
drwxrwxr-x 18 admin admin 612 26 Jul 12:47 /usr/local
which shows that its owned by admin (and in the admin group).
If I try to install node as Kramer using brew install node:
Error: Permission denied - /usr/local/Library/Locks/node.brewing
If I try to install node as admin (su admin, not sudo) using the same command I get:
Error: Cannot write to /usr/local/Cellar
I want to do this the right way, and not implement hacks. I thought I should be ok to use my admin account any time that I want to install anything with homebrew, and then revert back to my regular account Kramer for everyday coding. Am I wrong about this? Which account should be the owner of /usr/local/Cellar and /usr/local for me to achieve this?
Should /usr/local/Cellar owner be changed to admin (assuming I do installs with the admin account)?
Thanks.
You can totally use one account for dev and homebrew. You don't need sudo for homebrew installation or for further software installation like node or php.
Specifically for node.js you can use https://github.com/tj/n. It installs node binary in /usr/local/bin and it's pretty easy to control/update node.js version with it.
I'm not 100% sure, but I believe I installed node v5 from the windows installer on both my home and office PCs.
On my home PC global installs happen under %APPDATA%:
(dev) go|c:\srv> which lessc
c:\users\bjorn\appdata\roaming\npm\lessc
c:\users\bjorn\appdata\roaming\npm\lessc.cmd
while on my office PC, they go under program files:
(dev) go|w:\srv> which lessc
c:\program files\nodejs\lessc
c:\program files\nodejs\lessc.cmd
I need to provide the full path to a number of these global tools to PyCharm's file watcher, and since the project file i shared it would make sense to not have global resources under a user folder.
Why would the global installs end up in different folders, and how can I force them to a location that is common to all team members?
According to: https://docs.npmjs.com/files/folders
Local install (default): puts stuff in ./node_modules of the current package root.
Global install (with -g): puts stuff in /usr/local or wherever node is installed.
Install it locally if you're going to require() it.
Install it globally if you're going to run it on the command line. -> If you need both, then install it in both places, or use npm link.
prefix Configuration
The prefix config defaults to the location where node is installed. On
most systems, this is /usr/local. On windows, this is the exact
location of the node.exe binary.
The docs might be a little outdated, but they explain why global installs can end up in different directories:
(dev) go|c:\srv> npm config ls -l | grep prefix
; prefix = "C:\\Program Files\\nodejs" (overridden)
prefix = "C:\\Users\\bjorn\\AppData\\Roaming\\npm"
Based on the other answers, it may seem like the override is now the default location on Windows, and that I may have installed my office version prior to this override being implemented.
This also suggests a solution for getting all team members to have globals stored in the same absolute path relative to their PC, i.e. (run as Administrator):
(Run this in cmd, not in PowerShell!)
mkdir %PROGRAMDATA%\npm
setx PATH "%PROGRAMDATA%\npm;%PATH%" /M
npm config set prefix %PROGRAMDATA%\npm
open a new cmd.exe window and reinstall all global packages.
Explanation (by lineno.):
Create a folder in a sensible location to hold the globals (Microsoft is
adamant that you shouldn't write to ProgramFiles, so %PROGRAMDATA% seems
like the next logical place.
The directory needs to be on the path, so use setx .. /M to set the
system path (under HKEY_LOCAL_MACHINE). This is what requires you to run
this in a shell with administrator permissions.
Tell npm to use this new path. (Note: folder isn't visible in %PATH% in
this shell, so you must open a new window).
These are typical npm paths if you install a package globally:
Windows XP - %USERPROFILE%\Application Data\npm\node_modules
Newer Windows Versions - %AppData%\npm\node_modules
or - %AppData%\roaming\npm\node_modules
Just press windows button and type %APPDATA% and type enter.
Above is the location where you can find \npm\node_modules folder. This is where global modules sit in your system.
As of today, global packages installed like for eg. npm i -g #vue/cli are by default store in a directory:
C:\Users\<YourUserName>\AppData\Roaming\npm\node_modules
If you're just trying to find out where npm is installing your global module (the title of this thread), look at the output when running npm install -g sample_module
$ npm install -g sample_module C:\Users\user\AppData\Roaming\npm\sample_module ->
C:\Users\user\AppData\Roaming\npm\node_modules\sample_module\bin\sample_module.js
+ sample_module#5.1.0 updated 1 package in 2.821s
here is how I install react globally on windows,
npm install -g react
and I can see package installed at,
C:\Users\username\AppData\Roaming\npm\node_modules
I install node v14.9.0 using nvm and I find it in the D drive: D:\Users\<user_name>\AppData\Roaming\nvm\v14.9.0\node64.exe.
On my box I have the Node and NPM binaries installed under /opt/node/bin. And the path is added properly.
node -v
and
npm -v
work fine. When I create a file and run it with node all works as expected. However, when I run:
npm init
the program fails to write package.json because it does not have write permission. I use:
sudo npm init
I get a file with owner and group of 0 0 and so any regular users cannot modify this file. I don't want to have to chown every file node/npm generates.
Is there way to get node/npm to run as a user in the same group as my other users and have write permissions to the same directories?
You could simply chown your /opt/ directory and future calls to npm init will be owned by you. Better yet, work in your /home folder and make sure npm and node are in your $PATH. This way you don't need to worry about permissions for initializing a new node module. You will, however, need to use sudo to install packages globally. This is bad practice according to the maintainer of Nodejs:
http://howtonode.org/introduction-to-npm
I would follow along with his setup there. As he mentions, its very dangerous to give root access to a package manager.