nvm: You have $NVM_DIR set to "/root/.nvm", but that directory does not exist. Check your profile files and environment.

I’m trying to upgrade node. So I installed nvm. Still running on the old version of node. So I uninstalled it. Now running on the nvm version. Except some modules were compiled for old version. Delete node_modules. NPM install. Permission error installing with node-gyp. Google. Someone said you can’t use nvm as root. Uninstall NVM. Make another user. Install NVM. Error:

You have $NVM_DIR set to "/root/.nvm", but that directory does not exist. Check your profile files and environment.

Operating system and version:

ubuntu 16

nvm debug output:

nvm: command not found

nvm ls output:

nvm: command not found

How did you install nvm?

i didnt

What steps did you perform?

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash

What happened?

You have $NVM_DIR set to “/root/.nvm”, but that directory does not exist. Check your profile files and environment.

What did you expect to happen?

install nvm

Is there anything in any of your profile files that modifies the PATH?

probably maybe

If you are having installation issues, or getting “N/A”, what does curl -I --compressed -v https://nodejs.org/dist/ print out?

*   Trying 104.20.23.46...
* Connected to nodejs.org (104.20.23.46) port 443 (#0)
* found 129 certificates in /etc/ssl/certs/ca-certificates.crt
* found 516 certificates in /etc/ssl/certs
* ALPN, offering http/1.1
* SSL connection using TLS1.2 / ECDHE_RSA_AES_128_GCM_SHA256
*        server certificate verification OK
*        server certificate status verification SKIPPED
*        common name: *.nodejs.org (matched)
*        server certificate expiration date OK
*        server certificate activation date OK
*        certificate public key: RSA
*        certificate version: #3
*        subject: OU=Domain Control Validated,OU=PositiveSSL Wildcard,CN=*.nodejs.org
*        start date: Mon, 21 Oct 2019 00:00:00 GMT
*        expire date: Tue, 18 Jan 2022 23:59:59 GMT
*        issuer: C=GB,ST=Greater Manchester,L=Salford,O=Sectigo Limited,CN=Sectigo RSA Domain Validation Secure Server CA
*        compression: NULL
* ALPN, server accepted to use http/1.1
> HEAD /dist/ HTTP/1.1
> Host: nodejs.org
> User-Agent: curl/7.47.0
> Accept: */*
> Accept-Encoding: deflate, gzip
> 
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Date: Mon, 08 Feb 2021 20:10:01 GMT
Date: Mon, 08 Feb 2021 20:10:01 GMT
< Content-Type: text/html
Content-Type: text/html
< Connection: keep-alive
Connection: keep-alive
< Set-Cookie: __cfduid=d200ab00463901fee642fdd5f6f2dbdd31612815001; expires=Wed, 10-Mar-21 20:10:01 GMT; path=/; domain=.nodejs.org; HttpOnly; SameSite=Lax
Set-Cookie: __cfduid=d200ab00463901fee642fdd5f6f2dbdd31612815001; expires=Wed, 10-Mar-21 20:10:01 GMT; path=/; domain=.nodejs.org; HttpOnly; SameSite=Lax
< Cache-Control: max-age=14400
Cache-Control: max-age=14400
< CF-Cache-Status: HIT
CF-Cache-Status: HIT
< Age: 4768
Age: 4768
< cf-request-id: 0824dd0116000037faa20c4000000001
cf-request-id: 0824dd0116000037faa20c4000000001
< Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
< Vary: Accept-Encoding
Vary: Accept-Encoding
< Server: cloudflare
Server: cloudflare
< CF-RAY: 61e7fde1be7837fa-IAD
CF-RAY: 61e7fde1be7837fa-IAD
< Content-Encoding: gzip
Content-Encoding: gzip

< 
* Connection #0 to host nodejs.org left intact

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 24 (5 by maintainers)

Most upvoted comments

@skeddles So for example you might run sudo chown -R $(whoami) $HOME to do what @ljharb suggested, so that you no longer need the sudo. (the -R flag indicates recursive, so it will apply to every file inside the $HOME directory, which should be the same directory you navigate to via cd ~)

This is the equivalent of doing sudo chown -R lospec /home/lospec In case you need to change access modifiers, you can also do sudo chmod -R 755 $HOME where 755 should change to default values. edit: just like the other command -R is for recursive

Because I have no idea how to use linux

edit: here is the permissions of the home dir:

root@lospec-beta:/home/lospec/htdocs# ls -l $HOME
total 69492
-rw-r--r--   1 root root   357647 Apr 23  2018 export.json
-rw-r--r--   1 root root       13 Jun 21  2017 gitput.sh
-rw-r--r--   1 root root       47 Jun 25  2017 gitupdate.sh
-rw-r--r--   1 root root 70664728 Apr 29  2019 mongodb-compass-community_1.17.0_amd64.deb
drwxr-xr-x 271 root root    12288 Jan 21  2019 node_modules
-rw-r--r--   1 root root   108005 Jan 21  2019 package-lock.json

root@lospec-beta:/home/lospec/htdocs# su lospec

lospec@lospec-beta:~/htdocs$ ls -l $HOME
total 12
drwxr-xr-x 20 lospec lospec 12288 Feb  8 21:47 htdocs

edit: permissions are definitely bad.

lospec@lospec-beta:~/htdocs$ npm install npm ERR! code EACCES npm ERR! syscall mkdir npm ERR! path /home/lospec/.npm npm ERR! errno EACCES npm ERR! npm ERR! Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which has since been addressed. npm ERR! npm ERR! To permanently fix this problem, please run: npm ERR! sudo chown -R 1001:1002 “/home/lospec/.npm”

Ok, I think I figured it out. Use sudo npm install --unsafe-perm=true --allow-root instead

export NVM_DIR=$HOME/.nvm

after at you will be able to use:

calvez@docker-lara-prod:~$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 15037 100 15037 0 0 143k 0 --:–:-- --:–:-- --:–:-- 143k You have $NVM_DIR set to “/root/.nvm”, but that directory does not exist. Check your profile files and environment. calvez@docker-lara-prod:~$ export NVM_DIR=$HOME/.nvm calvez@docker-lara-prod:~$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 15037 100 15037 0 0 164k 0 --:–:-- --:–:-- --:–:-- 164k => Downloading nvm from git to ‘/home/calvez/.nvm’ => Cloning into ‘/home/calvez/.nvm’… remote: Enumerating objects: 355, done. remote: Counting objects: 100% (355/355), done. remote: Compressing objects: 100% (302/302), done. remote: Total 355 (delta 39), reused 168 (delta 28), pack-reused 0 Receiving objects: 100% (355/355), 208.50 KiB | 1.17 MiB/s, done. Resolving deltas: 100% (39/39), done.

  • (HEAD detached at FETCH_HEAD) master => Compressing and cleaning up git repository

=> Appending nvm source string to /home/calvez/.bashrc => Appending bash_completion source string to /home/calvez/.bashrc => Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR=“$HOME/.nvm” [ -s “$NVM_DIR/nvm.sh” ] && . “$NVM_DIR/nvm.sh” # This loads nvm [ -s “$NVM_DIR/bash_completion” ] && . “$NVM_DIR/bash_completion” # This loads nvm bash_completion

@skeddles So for example you might run sudo chown -R $(whoami) $HOME to do what @ljharb suggested, so that you no longer need the sudo. (the -R flag indicates recursive, so it will apply to every file inside the $HOME directory, which should be the same directory you navigate to via cd ~)

Ok, I think I figured it out. Use sudo npm install --unsafe-perm=true --allow-root instead

@Lucinotion Do you think they would have any security concerns with granting node that level of access though? Granted it might be the only way for this set up to work smoothly, but essentially scripts running in node would now have full system level privilege wouldn’t they? Probably a non-issue in this use case but just something to think of 🤷‍♂️

@skeddles In any case if the quoted solution works, awesome! Otherwise it looks like the npm cache is pointing at a location in that user home directory that doesn’t exist for that user (the “.npm” folder). npm cache clean --force might help reset that cache and then a clean npm install inside the directory where your package.json is located may work/show more useful errors.

Since node is installed at the right version now you should be right at the finish line here, just some ghosts of the journey to get here still causing bugs! Ha ha

He is right, the other solution would be to try to change all permissions and fix whatever permission mismatches are going on (search for info about EACCES), however now you should be able to do a sudo install.sh for the nvm (make sure that you can execute install.sh) or do a sudo bash install.sh , that should work too.

Also, have you done a npm init?

Could you also do a : apt list --installed | grep nodejs and apt list --installed | grep npm just to make sure if we could fix this by purging and reinstalling from apt

User management can be a nightmare when on Linux when you don’t deal with it every day, suddenly things work or don’t work and you have no idea what’s going on until things start crashing because of permissions errors and the inability to access directories etc.

So let’s see where we’re at here: my assumption is you’ve ssh’d into a remote Linux server (Ubuntu? If so which version) which is hosting a site dependant on node. If this is not a development server and is fact a beta hosting server it may be that NVM is not ideal for your use case as it’s unlikely you want to manage multiple Linux users and multiple node versions on this otherwise straight forward hosting server. (That isn’t to say NVM wouldn’t be useful, but it might be overkill for your current stage of development).

To figure out next steps: Are my assumptions so far correct? And what is the current install state of node on your system (for example what happens when your run ‘which node’ or ‘node --version’ or even ‘npm -v’)?

I’m not sure what tool you’re using, but generally you provide the username you’re logging in with as part of the connection.

Either way, you can unset $NVM_DIR after su and it should be fine.