'NVM: Getting Permission denied with nvm install command
I recently fresh-installed Ubuntu 21.04 and wanted to install nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
Then closed and re-opened the terminal. When requesting an install of version 12.16.3
(have tried with other versions as well). I'm getting the following error:
nvm install 12.16.3
Downloading and installing node v12.16.3...
Downloading https://nodejs.org/dist/v12.16.3/node-v12.16.3-linux-x64.tar.xz...
Warning: Failed to create the file
Warning: /home/sauronnikko/.nvm/.cache/bin/node-v12.16.3-linux-x64/node-v12.16.
Warning: 3-linux-x64.tar.xz: Permission denied
curl: (23) Failure writing output to destination
Binary download from https://nodejs.org/dist/v12.16.3/node-v12.16.3-linux-x64.tar.xz failed, trying source.
grep: /home/sauronnikko/.nvm/.cache/bin/node-v12.16.3-linux-x64/node-v12.16.3-linux-x64.tar.xz: No such file or directory
Provided file to checksum does not exist.
Binary download failed, trying source.
Downloading https://nodejs.org/dist/v12.16.3/node-v12.16.3.tar.xz...
Warning: Failed to create the file
Warning: /home/sauronnikko/.nvm/.cache/src/node-v12.16.3/node-v12.16.3.tar.xz:
Warning: Permission denied
curl: (23) Failure writing output to destination
Binary download from https://nodejs.org/dist/v12.16.3/node-v12.16.3.tar.xz failed, trying source.
grep: /home/sauronnikko/.nvm/.cache/src/node-v12.16.3/node-v12.16.3.tar.xz: No such file or directory
Provided file to checksum does not exist.
Solution 1:[1]
Posted an issue to nvm's repo
Turns out the problem was with curl
and that I had installed it with snap
instead of regular apt install curl
.
Solution 2:[2]
uninstall curl
installed with snap
sudo snap remove curl
install curl
from apt
sudo apt install curl
Solution 3:[3]
I had the same issue. It was due to the lack of "libssl-dev". Run the following command before you start the installation process for nvm
sudo apt-get install build-essential libssl-dev curl git-core
Solution 4:[4]
I had the same issue (having previously installed curl with snap). After UNinstalling curl nvm worked as expected.
$ sudo snap remove curl
Solution 5:[5]
It says Permission denied
, try the same command with sudo
sudo curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
Solution 6:[6]
I have had the exact same issue today as well, I'm not sure if its been an issue with NVM or if its just my Linux install being screwy but I have managed to get around it for the moment by manually downloading the tar file for the node version you want to install, move it to nvm's cache and then running nvm install again. I'll leave exact steps below and I'll try and remember to come back and update this Q if I work out why curl doesnt want to create a file in the .nvm dir
I have tried everything I can think of to try allow curl to save to the nvm directory, installing nvm using sudo, chown the dir, add full rwx permissions for user group and other for the dir, manually install nvm, nothing had worked for me so at present my best solution is below :)
Work around fix (using v16.1.0 of node as the example):
1 - run the curl command to download the version of node you want into your home directory
curl https://nodejs.org/dist/v16.1.0/node-v16.1.0-linux-x64.tar.xz --output node-v16.1.0-linux-x64.tar.xz
2 - copy the file to the nvm cache
sudo mv node-v16.1.0-linux-x64.tar.xz ~/.nvm/.cache/bin/node-v16.1.0-linux-x64/node-v16.1.0-linux-x64.tar.xz
3 - run nvm install again
nvm install node (or whatever version you are trying to install)
Solution 7:[7]
This worked
In simple words i did this and it worked...
>snap list
>sudo snap remove curl
This will delete curl that was installed through snap. We need to install using apt
>sudo apt-get install curl
Now we need to install nvm using curl
>curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
Now simply install the node version u want.
>nvm install v14.17.0
In order to list all nvm version simply do so.
>nvm ls
And in order to switch just type the following command.
>nvm use v12.X.XX
Solution 8:[8]
check your NVM_DIR environment variable, mine was set incorrectly after transferred from an older machine
Solution 9:[9]
You can try creating folder and giving write permission to it:
Create folder
mkdir ~/.nvm
Give permission for example:
sudo chmod 777 ~/.nvm
Note :In my case, I passed these steps, but I got another permission error during installation of a node version with nvm, and solved it by using this command:
sudo chmod 777 /private/tmp
Solution 10:[10]
For me the problem was different, and the solution was to create an SSH Key for GitHub and add it in my profile.
See related documentation here
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow