Clear your Proxy settings in NPM or npm install behind proxy

avatar
Borislav Hadzhiev

Last updated: Apr 4, 2024
5 min

banner

# Table of Contents

  1. How to clear (or reset) your Proxy settings in NPM
  2. Unset the Proxy environment variables in NPM
  3. Disabling SSL key validation when making requests
  4. rollbackFailedOptional: verb npm-session
  5. Editing your proxy settings manually in your .npmrc file
  6. Using npm install from behind a proxy

# How to clear (or reset) your Proxy settings in NPM

Issue the npm config rm proxy command to clear your proxy settings in NPM.

The command will delete the proxy key from all configuration files.

shell
npm config rm proxy

npm config rm proxy

After you run the npm config rm proxy command, run the following 2 commands as well.

shell
npm config rm http-proxy npm config rm https-proxy

clear http and https proxy in npm

You can use the npm config list command to print your npm configuration, including your proxy settings.

verify proxy settings cleared

Your proxy settings should be reset after issuing the npm config rm commands.

If the issue persists, set the --global flag when running the commands.

shell
npm config --global rm proxy npm config --global rm http-proxy npm config --global rm https-proxy

clear proxy using global flag

If the issue persists, try using the npm config delete alias instead.

shell
npm config delete proxy

npm config delete proxy

After you issue the npm config delete proxy command, run the following 2 commands.

shell
npm config delete http-proxy npm config delete https-proxy

npm config delete http and https proxy

# Unset the Proxy environment variables in NPM

Even if the proxy settings are not set, they might get pulled from the http_proxy and https_proxy environment variables.

To completely clear your proxy settings, unset the environment variables.

If you are on Windows, issue the following commands in CMD to print your proxy settings.

cmd
# Windows CMD echo %http_proxy% echo %https_proxy%

If you are on macOS or Linux, issue the following commands to print your proxy settings.

shell
# macOS and Linux echo $http_proxy echo $https_proxy

To clear your proxy settings on Windows, use the set command in CMD.

cmd
# for Windows CMD (Command Prompt) set http_proxy=null set https_proxy=null set HTTP_PROXY=null set HTTPS_PROXY=null

If you use PowerShell, issue the following commands instead.

PowerShell
# for Windows CMD (PowerShell) [Environment]::SetEnvironmentVariable('http_proxy', '', 'User') [Environment]::SetEnvironmentVariable('http_proxy', '', 'Machine') [Environment]::SetEnvironmentVariable('https_proxy', '', 'User') [Environment]::SetEnvironmentVariable('https_proxy', '', 'Machine')

If you are on macOS or Linux, use the unset command to clear your proxy settings.

shell
# for macOS, Linux or Windows Git Bash unset http_proxy unset https_proxy unset HTTP_PROXY unset HTTPS_PROXY

# Disabling SSL key validation when making requests

If you still aren't able to clear your proxy NPM settings, try to set the strict-ssl setting to false.

The setting determines whether to do SSL key validation when making requests to the registry via HTTPS.

shell
npm config set registry http://registry.npmjs.org/ npm config set strict-ssl false

You can always switch the strict-ssl setting to true by issuing the following command.

shell
npm config set strict-ssl true

Notice that the registry URL uses the http protocol (and not https).

# rollbackFailedOptional: verb npm-session

If you get the "rollbackFailedOptional: verb npm-session" error when running the npm install command, clear your proxy settings and update your NPM registry.

shell
npm config rm proxy npm config rm http-proxy npm config rm https-proxy

After you clear your proxy, set your registry to https://registry.npmjs.org/ .

shell
npm config set registry https://registry.npmjs.org/

# Editing your proxy settings manually in your .npmrc file

If you need to clear or set your proxy settings manually, you have to edit your .npmrc file.

On Windows, the file is usually under %USERPROFILE%\.npmrc or C:\Program Files\nodejs\node_modules\npm\npmrc.

On Linux and macOS, the file is located under ~/.npmrc.

If you can't find your .npmrc file, try issuing the npm config list command.

shell
npm config list

find your npmrc config file

The output of the command shows that my .npmrc file is located under /home/borislav/.npmrc.

If you want to clear your NPM proxy settings, open your .npmrc file and remove the following properties:

  • proxy
  • http-proxy
  • https-proxy

Conversely, if you want to set the proxy settings, set the proxy and https-proxy keys.

~/.npmrc
proxy=http://YOUR_PROXY.com:5050 https-proxy=http://YOUR_PROXY.com:5050

The syntax for the URL is http://<host>:<port>.

You can also set the proxy settings using the command line.

shell
npm config set proxy http://YOUR_PROXY:5050 npm config set https-proxy http://YOUR_PROXY:5050

Once you set your proxy settings correctly, you should be able to use the npm install command without any issues.

# Using npm install from behind a proxy

If you need to use the npm install command from behind a proxy:

  1. Disable the strict-ssl setting.
shell
npm config set strict-ssl false

The setting determines whether to do SSL key validation when making requests to the registry via HTTPS.

  1. Set the protocol of the registry to http instead of https.
shell
npm config set registry "http://registry.npmjs.org/"
  1. Set the --proxy flag when issuing the npm install command.
shell
npm --proxy http://USERNAME:PASSWORD@proxy.company:8080 install YOUR_PACKAGE

If your password contains an @ symbol, wrap the username and password in double quotes.

If your proxy doesn't require authentication, omit the USERNAME:PASSWORD@ part.

shell
npm --proxy http://proxy.company:8080 install YOUR_PACKAGE

You can also use the npm config command to set your proxy settings in your .npmrc file.

shell
# for HTTP npm config set proxy http://proxy.company:8080

If your company also has an HTTPS address, set the https-proxy key.

shell
# for HTTPS npm config set https-proxy https://proxy.company:8080

If your company doesn't have an HTTPS address, set the https-proxy key using the http protocol and reuse the HTTP proxy address.

shell
# for HTTPS npm config set https-proxy http://proxy.company:8080

If you still aren't able to run the npm install command without running into issues, set the HTTP_PROXY and HTTPS_PROXY environment variables.

If you are on macOS or Linux or use Git Bash on Windows, use the export command.

shell
# For macOS or Linux # Without a username and a password export http_proxy=http://proxy.company:8080 export HTTP_PROXY=http://proxy.company:8080 # Or with a username and a password export https_proxy=http://USERNAME:PASSWORD@proxy.company:8080 export HTTPS_PROXY=http://USERNAME:PASSWORD@proxy.company:8080

If you are on Windows and use CMD, use the set command.

shell
# For Windows # Without a username and a password set HTTP_PROXY=http://proxy.company:8080 # Or with a username and a password set HTTPS_PROXY=http://USERNAME:PASSWORD@proxy.company:8080

Set the --strict-ssl setting to false.

shell
npm config set strict-ssl false

And try to issue the npm install command.

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.