n: Permission denied before running with sudo
Issue Template:
Describe issue including what OS you are using
After installing n on macOS 10.12.3 and node 7.5.0 previously installed, I ran simply n and got “permission denied” issues along stating that I hadn’t any version installed along the list of possible commands.
Then I ran one command with sudo and the “permission denied” issue disappeared.
Describe what version of N you have
2.1.4
Describe how you installed N
npm install -g n
Steps to reproduce issue 1.2.3
- install n for the first time
- run n
- get issue
Describe the results you received
permission denied for operations along with list of possible commands
Describe the results you expected
list of possible commands
What version of npm you are using
4.1.2
Additional information you deem important (e.g. issue happens only occasionally):
- Output of
which n:/usr/local/bin/n - Output of
node -v:v7.5.0
(paste your output here)
tiago at Tiagos-MacBook-Pro in ~
$ n
mkdir: /usr/local/n/versions/node: Permission denied
mkdir: /usr/local/n/versions/io: Permission denied
find: /usr/local/n/versions: No such file or directory
Error: no installed version
$ n -V
mkdir: /usr/local/n/versions/node: Permission denied
mkdir: /usr/local/n/versions/io: Permission denied
2.1.3
tiago at Tiagos-MacBook-Pro in ~
$ sudo n -V
Password:
2.1.3
tiago at Tiagos-MacBook-Pro in ~
$ node
> .exit
tiago at Tiagos-MacBook-Pro in ~
$ sudo n
Error: no installed version
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 3
- Comments: 17
I did these
ndirectory in /user/localsudo chown -R $(whoami) /usr/local/nnow it’s work.
The original posters problem is that
nreports a permission error the first time it is run. The underlying reason this happens is becausenis checking its cache folders exist every time it is run.Assuming you want to do node installs to
/usr/local/(which is the default forn):If you will use
sudowhen you run installs, simplest is just runsudo nonce and it will create the necessary folders as a side-effect. After doing that, you can run read-only commands likenandn --ltswithout sudo.If you do not wish to use
sudofor installs and are in control of the computer, you can take ownership of the cache folder and install locations. (This ownership change also allows npm installs of global packages without using sudo.)I also had to run
sudo chown -R $(whoami) /usr/local/lib/node_modules/This should really be in the ReadMe, I can’t use n without changing ownership and I had to find this issue ti get it working.
Is there any reason these steps are not in the README? I’d be happy to add them and submit a PR.
You don’t own the folder
/usr/local/so executing anything will have to come from sudo. If youchownthe directory, using sudo will not be necessary fornIf you ever had brew installed they do that for you.
So for your issue, sudo is the way you need to go to use n.
Note that as of 2017 homebrew no longer changes the ownership of this folder. You will have to do it yourself.
Since, High Sierra doesn’t allow
chownon/usr, the following solved this issue for me (OS 10.13.6):Reference.
I also had to run
There are lots of upvotes for work-arounds and README despite being a closed issue. Reopening to increase visibility, until fixed.
I would like to point out: it’s not recommended to chown /usr/local, only the directory needed inside… I mean that whole directory was classified root only, if you reduce that security level, some apps could change/create files in that directory which are eventually executed by root later… => obvious isn’t it? or do you think the Apple team sets /usr/local back to root on every release just to annoy you? 😃
Removed need for
sudofor read-only operations. Addedchowntips toREADME. Fixed in v3.0.2.