# Error: EACCES: permission denied, access '/usr/local/lib/node_modules'

The error `Error: EACCES: permission denied, access '/usr/local/lib/node_modules'` typically occurs when you try to install global npm packages without the necessary permissions. This can happen if you are trying to install packages using `npm install -g` without superuser privileges.

Here are a few solutions to fix this issue:

## Use `sudo` (not recommended)

You can use the `sudo` command to install npm packages with elevated privileges:

```bash
sudo npm install -g <package-name>

```

However, using `sudo` with npm is generally not recommended because it can lead to permission issues and might cause problems later. If you choose this approach, be cautious and understand the implications.

## Change npm's default directory

You can configure npm to install global packages in a directory where you have write permissions without using `sudo`. Choose a directory that does not require superuser privileges.

1. Create a directory for global npm packages in your home directory:
    
    ```bash
    mkdir ~/.npm-global
    ```
    
2. Configure npm to use this directory:
    
    ```bash
    npm config set prefix '~/.npm-global'
    ```
    
3. Add the following line to your `~/.bashrc` or `~/.zshrc` file to include the new directory in your PATH:
    
    ```bash
    export PATH=~/.npm-global/bin:$PATH
    ```
    
4. Restart your terminal or run:
    
    ```bash
    source ~/.bashrc
    ```
    

Now you should be able to install global npm packages without using `sudo`:

```bash
npm install -g <package-name>

```

## Use a Node version manager

Consider using a Node version manager like NVM (Node Version Manager) or Nodenv. These tools allow you to install Node.js and npm without requiring superuser privileges.

- [NVM](https://github.com/nvm-sh/nvm)
- [Nodenv](https://github.com/nodenv/nodenv)

Choose the option that best fits your needs and system configuration. Using a version manager is generally recommended for managing Node.js installations and avoiding permission issues.