I'm facing this error when I'm trying to install Angular CLI. Please help me with the issue:

npm ERR! code E401
npm ERR! Unable to authenticate, need: Basic realm="Artifactory Realm"

In my case, I have set registry via npm config set registry <corporate_registry_url> an authenticated via npm login and I had this 401 error until I've added to .npmrc this line


after the following line


This way, token got applied and installation of a package succeeded.


Looks like you're running into authentication issues with your company's internal npm registry. I'd try one of these solutions:

  • Talk with your DevOps team and figure out why your login isn't working. This is the type of thing that a company ought to document in a wiki or similar place.
  • Try adding --registry https://registry.npmjs.org to your npm commands in the short term. This will install from the public registry, which you should not need to authenticate to.

If you run npm config ls, you will likely see a registry line. There should be a filename above it ending in .npmrc; if you edit this file you can change the registry to the public one. (Usually it's ~/.npmrc but may depend on your configuration.)

  • 1
    Usually people use a local registry because their firewalls restrict access such that they can't connect the registry.npmjs.org. If that is the case, your suggestion won't work. – Lee Meador Apr 24 '20 at 18:22

I was trying to setup npm for the first time on my laptop. My corporate npm registry is in Artifactory. I had configured my auth through the .npmrc file by adding the below details to it (as suggested in Artifactory "set me up"):


The error (npm ERR! Unable to authenticate, need: Basic realm="Artifactory Realm") got resolved after removing underscore (_) from auth in the .npmrc file:

  • This actually worked ! tried so many things but this is what actually worked ...Thanks ! – Zaid Nov 2 '20 at 15:36

It helps if you post your NPM configs. Use npm config ls to see what registry you have set up. I ran into a similar error message and my solution was to set the registry as secured HTTP: registry=https://.... I'm also using my job's Artifactory server. Once you set the registry, you can try authenticating against the Artifactory registry using npm login, which will prompt you for username, password, and the e-mail address associated with your Artifactory registry account.

This Artifactory endpoint will retrieve an encrypted auth token (which can be used for reaching the Artifactory API) and e-mail:

curl -vv -<username>:<encrypted-password> http://<ARTIFACTORY-HOST</artifactory/api/npm/auth

You can get <encrypted-password> usually by going to your Artifactory account in the browser at https://<artifactory-host>/artifactory/webapp/#/profile.

Sample output:

_auth = <encrypted-auth-token>
always-auth = true
email = joe.smith@somehost.com

Adding following in .npmrc worked for me:

_auth = <Basic_Authentication_Header>
email = myemail@email.com
always-auth = true

Online utility which can help to generate Basic Authentication Header can be found here - https://www.blitter.se/utils/basic-authentication-header-generator/

  • 1
    Thanks, this actually worked for me too. Had to add scope at the top as well: @jfrog:registry=https://yourcompany.registry.com/artifactory then running npm install --scope=jfrog --save package-name worked like a charm – Maksim Luzik Mar 25 at 10:30

What worked for me:

  1. Ran

npm config ls

Look for the location/path of where .npmrc - next to text: userconfig

  1. Go to that location/path then delete the .nprmc file

  2. Ran the in npm install command - e.g:

npm install cypress --save-dev

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.