DEV Community

Mario García
Mario García

Posted on • Edited on

Installing near-cli on Linux

Recently started learning about Near Protocol and while I was completing the exercises at Near Academy, I got some error when I was trying to install near-cli on Arch Linux.

For installing near-cli you must have Node.js and npm on your system. You can install them directly from the repositories of your distribution.

After running npm install near-cli -g I was getting the following error:

npm ERR! code 128
npm ERR! command failed
npm ERR! command git ls-remote ssh://git@github.com/ethereumjs/ethereumjs-abi.git
npm ERR! Warning: Permanently added 'github.com' (RSA) to the list of known hosts.
npm ERR! git@github.com: Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
npm ERR! 
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
Enter fullscreen mode Exit fullscreen mode

It was an authentication problem with GitHub. One possible solution was to create a new SSH key, add it to the ssh-agent and to my GitHub account. I did it but didn't work as I was getting a different error, even if I was running the command as the root user:

npm ERR! code 128
npm ERR! command failed
npm ERR! command git clone ssh://git@github.com/ethereumjs/ethereumjs-abi.git /root/.npm/_cacache/tmp/git-clone-e04f6db7 --recurse-submodules --depth=1
npm ERR! fatal: could not create leading directories of '/root/.npm/_cacache/tmp/git-clone-e04f6db7': Permission denied
Enter fullscreen mode Exit fullscreen mode

I tried to install near-cli on a virtual environment with Fedora 32 where the latest version of Node.js was 12.22.1, it worked without any problem. On Fedora 33 and Debian Buster I was getting the same error.

Solution

Manually change npm's default directory, according to the Node.js documentation, is the way of Resolving EACCES permissions errors when installing packages globally.

After installing Node.js and npm:

Create a directory for global installations:

$ mkdir ~/.npm-global
Enter fullscreen mode Exit fullscreen mode

Configure npm to use the new directory path:

$ npm config set prefix '~/.npm-global'
Enter fullscreen mode Exit fullscreen mode

Open or create a ~/.profile file and add this line:

export PATH=~/.npm-global/bin:$PATH
Enter fullscreen mode Exit fullscreen mode

Update your system variables:

$ source ~/.profile
Enter fullscreen mode Exit fullscreen mode

Now you can install near-cli by running the following command without sudo:

$ npm install near-cli -g
Enter fullscreen mode Exit fullscreen mode

You're good to go! Now you have the tool you require for completing the exercises at Near Academy.

Top comments (1)

Collapse
 
drawmardock profile image
drawmardock

thanks that's help me for another trouble i found