Showing posts with label nodejs. Show all posts
Showing posts with label nodejs. Show all posts

How to fix checkPermissions Missing write access to /usr/local/lib/node_modules error ?

If you are working in a Node JS environment and without root access or sudo access, you might get an error as checkPermissions Missing write access to /usr/local/lib/node_modules like below

npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /usr/local/lib/node_modules
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!  [Error: EACCES: permission denied, access '/usr/local/lib/node_modules'] {
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules'
npm ERR! }
npm ERR!

one solution to this problem is changing the permission of the folder /usr/local/lib/node_modules for the current user, but thats not recommended and what if its not in your hands to change the permission.
One thing we can do to address this problem is modify the location where nodejs can store modules, for your user account.
Follow below steps in given order to configure your node_modules folder for your user account with out harming others!!

# Create a directory named npm-global as hidden in your home directory
mkdir ~/.npm-global

# Then set it as your node dir 
npm config set prefix '~/.npm-global'

# Update Path in your .bashrc or .bash_profile or .profile files as below
export PATH="~/.npm-global/bin:$PATH"

# once saved load the changes
source ~/.bashrc

And thats it, we are good. Now you can install any module and you wont be getting any permission related error as above.
Hope it helps.

How to install nodejs in CentOS ?

If you choose default yum install of nodejs you will get 6.x release which is very old.
To install latest version of nodejs in centos you can execute below command
Command 1
  
  	curl -sL https://rpm.nodesource.com/setup_14.x | sudo bash -
   

You will get output as below

[vagrant@localhost ps-sinonjs]$ curl -sL https://rpm.nodesource.com/setup_14.x | sudo bash -

## Installing the NodeSource Node.js 14.x repo...


## Inspecting system...

+ rpm -q --whatprovides redhat-release || rpm -q --whatprovides centos-release || rpm -q --whatprovides cloudlinux-release || rpm -q --whatprovides sl-release
+ uname -m

## Confirming "el7-x86_64" is supported...

+ curl -sLf -o /dev/null 'https://rpm.nodesource.com/pub_14.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm'

## Downloading release setup RPM...

+ mktemp
+ curl -sL -o '/tmp/tmp.KNA1QsAK2D' 'https://rpm.nodesource.com/pub_14.x/el/7/x86_64/nodesource-release-el7-1.noarch.rpm'

## Installing release setup RPM...

+ rpm -i --nosignature --force '/tmp/tmp.KNA1QsAK2D'

## Cleaning up...

+ rm -f '/tmp/tmp.KNA1QsAK2D'

## Checking for existing installations...

+ rpm -qa 'node|npm' | grep -v nodesource

## Run `sudo yum install -y nodejs` to install Node.js 14.x and npm.
## You may also need development tools to build native addons:
     sudo yum install gcc-c++ make
## To install the Yarn package manager, run:
     curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
     sudo yum install yarn


Your main instructions are here

## Run `sudo yum install -y nodejs` to install Node.js 14.x and npm.
## You may also need development tools to build native addons:
     sudo yum install gcc-c++ make
## To install the Yarn package manager, run:
     curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
     sudo yum install yarn

I mean simply after executing command1 you can execute below commands and it will install latest Node.js version for you.

 sudo yum install -y nodejs 
 sudo yum install gcc-c++ make
 curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
 sudo yum install yarn
Hope it helps.
Thank you for reading the article.