Last updated: Apr 4, 2024
Reading time·5 min
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.
npm config rm proxy
After you run the npm config rm proxy
command, run the following 2 commands as
well.
npm config rm http-proxy npm config rm https-proxy
You can use the npm config list command to print your npm configuration, including your proxy settings.
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.
npm config --global rm proxy npm config --global rm http-proxy npm config --global rm https-proxy
If the issue persists, try using the npm config delete
alias instead.
npm config delete proxy
After you issue the npm config delete proxy
command, run the following 2
commands.
npm config delete http-proxy npm config delete https-proxy
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.
# Windows CMD echo %http_proxy% echo %https_proxy%
If you are on macOS or Linux, issue the following commands to print your proxy settings.
# macOS and Linux echo $http_proxy echo $https_proxy
To clear your proxy settings on Windows, use the set
command in 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.
# 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.
# for macOS, Linux or Windows Git Bash unset http_proxy unset https_proxy unset HTTP_PROXY unset HTTPS_PROXY
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.
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.
npm config set strict-ssl true
Notice that the registry URL uses the http
protocol (and not https
).
If you get the "rollbackFailedOptional: verb npm-session" error when running
the npm install
command, clear your proxy settings and update your NPM
registry.
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/
.
npm config set registry https://registry.npmjs.org/
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.
npm config list
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.
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.
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.
If you need to use the npm install
command from behind a proxy:
strict-ssl
setting.npm config set strict-ssl false
The setting determines whether to do SSL key validation when making requests to the registry via HTTPS.
http
instead of https
.npm config set registry "http://registry.npmjs.org/"
--proxy
flag when issuing the npm install
command.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.
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.
# for HTTP npm config set proxy http://proxy.company:8080
If your company also has an HTTPS address, set the https-proxy
key.
# 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.
# 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.
# 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.
# 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
.
npm config set strict-ssl false
And try to issue the npm install
command.
You can learn more about the related topics by checking out the following tutorials: