3

I need to install yarn without sudo. I do this:

$ npm install -g yarn

and I get this:

npm ERR! code EACCES
npm ERR! syscall symlink
npm ERR! path ../lib/node_modules/yarn/bin/yarn.js
npm ERR! dest /usr/bin/yarn
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, symlink '../lib/node_modules/yarn/bin/yarn.js' -> '/usr/bin/yarn'
npm ERR!  [OperationalError: EACCES: permission denied, symlink '../lib/node_modules/yarn/bin/yarn.js' -> '/usr/bin/yarn'] {
npm ERR!   cause: [Error: EACCES: permission denied, symlink '../lib/node_modules/yarn/bin/yarn.js' -> '/usr/bin/yarn'] {
[.........]

But:

ls -al /usr/lib/node_modules/

drwxr-xr-x  5 user1 user1  4096 Sep 15 05:13 .
drwxr-xr-x 63 root  root  32768 Sep 14 15:18 ..
drwxr-xr-x  9 user1 user1  4096 Sep 14 14:48 node-gyp
drwxr-xr-x  9 user1 user1  4096 Sep 15 04:22 npm
drwxr-xr-x  7 user1 user1  4096 Sep 14 14:48 semver

And

$ ls -ald /usr/lib/node_modules/
drwxr-xr-x 5 user1 user1 4096 Sep 15 05:13 /usr/lib/node_modules/

Why and how to fix it?

RobC
  • 22,977
  • 20
  • 73
  • 80
kosmosu
  • 63
  • 1
  • 1
  • 6

1 Answers1

2

Your config folder must be owned by root, which creates several permissions issue. Changing it to the current user will solve it

$USER:$GROUP -> gives the current login user and the group. in the terminal you can try to echo $USER echo $GROUP to know its value. By this command, it will change to the value present in $USER. The same applies for the group too.

sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config

now try all your commands

replication of https://github.com/bower/bower/issues/2262

Jatin Mehrotra
  • 9,286
  • 4
  • 28
  • 67
  • what's `$GROUP`? – kosmosu Sep 15 '20 at 05:53
  • `drwxr-xr-x 5 user1 user1 4096 Sep 15 05:13 /usr/lib/node_modules/` the second user1 is the entry for group.In linux a group is a collection of users. The main purpose of the groups is to define a set of privileges like read, write, or execute permission for a given resource that can be shared among the users within the group. Users can be added to an existing group to utilize the privileges it grants. – Jatin Mehrotra Sep 15 '20 at 05:59
  • Did it worked for you? – Jatin Mehrotra Sep 15 '20 at 06:00
  • I'm asking what value does a `GROUP` have to have in this case. The same question for `USER` – kosmosu Sep 15 '20 at 06:05
  • $USER:$GROUP -> gives the current login user and the group. in terminal you can try echo $USER echo $GROUP to know its value. By this command it will change to the value present in $USER. same applies for group too. the value should be the user who is running command `npm install -g yarn` which i think it should be user1 – Jatin Mehrotra Sep 15 '20 at 06:13
  • what's terminal? – kosmosu Sep 15 '20 at 06:28
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/221491/discussion-between-jatin-mehrotra-and-kosmosu). – Jatin Mehrotra Sep 15 '20 at 06:29
  • Nooooooooooooooo. Here! – kosmosu Sep 15 '20 at 06:42
  • its command prompt, in linux language its called terminal., if it helped you please accept it as a solution to your question, so that in the future it may help others. – Jatin Mehrotra Sep 15 '20 at 06:43
  • what's linux?.... – kosmosu Sep 15 '20 at 06:56
  • 9
    This solution did not work for me – Alan P. Jan 08 '21 at 17:20
  • Thank you but I have this err and yet my config folder was owned properly. – R Claven Jan 26 '21 at 23:13