Unable to run npm commands with sudo - npm

I've recently installed the balena-cli package via npm (which itself has been installed using nvm) which works fine when accessed from my default user.
However whenever I try to access npm, nvm or balena-cli using sudo they all print the following error
$ sudo npm
sudo: npm: command not found
$ sudo nvm
sudo: nvm: command not found
$ sudo balena
sudo: balena: command not found
I tried using sudo chown on all 3 but to now avail.
Basically, none of the Node related functions can be accessed using root.
Any suggestions on how to resolve this, perhaps by the use of environment variables?

As a stop gap, I found out that running the same command after switching to root works fine with the following command;
$ sudo -s
However, since it's a stop gap, it would be great to find a way to run the same commands without switching back and forth between root.

Basically once do check that have you flashed Balena image correctly and then check the network permissions and login to Balena with root and run commands with su instead of sudo then your issue might clear.

Related

not able to install anything because of brew no such file or directory error

I am trying to install do brew install python3 on my mac but i keep getting the following errors:
this is the first error:
No such file or directory # dir_chdir - /usr/local/Cellar
then a bit later i get this error:
An exception occurred within a child process:
Errno::EPERM: Operation not permitted # dir_s_mkdir - /usr/local/Cellar
I have ran brew update then brew doctor the brew cleanup but keep getting the error.
I have also checked to see if xcode is up-to-date but according to the appstore all my apps are up-to-date.
How do i fix this problem?
PS i also get these errors when trying to install other packages from brew.
Try uninstalling Homebrew and then re-installing solved issue for me.
Uninstall Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
Re-install Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Performed in MacOS Mojave (10.14.4)
Happened to me when uninstalling Laravel Valet.
Fixed by running: brew doctor, then brew cleanup after.
After that - brew install php worked just fine.
I experienced a similar error with a different package - brew install llvm.
Uninstalling homebrew and reinstalling led to more catastrophic issues that lasted for hours before I had to reach for my backup drive and restore everything.
What eventually worked was just creating the missing directory and everything worked.
So in this case:
sudo mkdir /usr/local/Cellar/dir_chdir
should solve the issue without too much hustle.
It worked for me after running below commands
sudo mkdir /usr/local/Cellar/dir_chdir
sudo chown -R $(whoami) /usr/local/Cellar
chmod u+w /usr/local/Cellar
I had this problem as well - it was partly coming from brew being installed under a different user on my mac I had set up for a past project. I had to follow the uninstall instructions (found in the homebrew github) with a little bit of sudo help and it cleared up the issue. Was able to install and properly run packages after.
For ubuntu just go to the location which u are getting error. Then open the contained file using a suitable application. In my case, it is getting as follows in the image view.
In this case, the error is showing in 36's lines.
yes. There is no location such as. I have to find out the location which contains brew. It was in /home/linuxbrew/.linuxbrew//bin/brew shellenv
So update your .profile file as in the brew file contains location as follows image shown.
uninstall brew :
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh)"
and again reinstall brew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
executed this same as it is on your terminal, it will really work.

What is going on and how do I fix it?

https://prnt.sc/hlt4ey
I'm trying to get onto the xfce4 client from my chromebook (and it has worked before), however now this error is popping up. How do I fix this error?
My guess is you may not have the right user privileges. According to the error message you provided you are running an Ubuntu Linux environment.
If you haven't tried running the program through the terminal yet, attempt to do so.
The terminal can typically be opened by the key combination Ctrl+Alt+T on ubuntu linux.
Try using sudo command before running the program. This will run the command you enter using root privileges.
For example, if running the program on your terminal is
myName#ubuntu: xfce4
And this encounters an error, try to use sudo beforehand like so:
myName#ubuntu: sudo xfce4
Alternatively you can log in and not have to type sudo before every command.
myName#ubuntu: sudo bash
password:
If this fails you may need to update the package that contains the library. This can be done on the terminal in a fashion similar to:
myName#ubuntu: sudo apt-get install --only-upgrade xfce4

npm install error `not foundram Files/nodejs/npm: 3: /mnt/c/Program Files/nodejs/npm:`

I have installed Ubuntu Bash on Windows. I already have nodejs and npm on my windows machine at C:\Program Files\nodejs. In the bash shell in Windows, I am running a script which uses npm install command. The script is giving following error
: not foundram Files/nodejs/npm: 3: /mnt/c/Program Files/nodejs/npm:
: not foundram Files/nodejs/npm: 5: /mnt/c/Program Files/nodejs/npm:
/mnt/c/Program Files/nodejs/npm: 6: /mnt/c/Program Files/nodejs/npm: Syntax error: word unexpected (expecting "in")
Note: Before following the steps below, first try to restart your shell.
You can install Node.js and NPM with your Windows PowerShell as well, so if you've done that it won't work properly for your Subsystem. That means you have to install it twice (Powershell and Subsystem) or decide on one thing.
If the preceding text, has not helped you, this is how to solve the problem:
Remove your current installations
sudo apt-get --purge remove node
("sudo apt autoremove node" if console is asking for it)
sudo apt-get --purge remove nodejs
Install node the right way.
This is for version 14 (view current LTS version):
curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
sudo apt-get install -y nodejs
Then install build tools so you can install add-ons for npm later
sudo apt-get install -y build-essential
Now you can type in
npm -v
node -v
Same thing: nodejs -v
to check whether Node.js and NPM are installed correctly. If it shows nothing, restart the shell.
If it still shows the same error, restart the WSL/ PC or try with sudo npm -v
Here are two links that may also help you.
https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions
https://github.com/nodesource/distributions/blob/master/README.md#debinstall
Also, take a look at the Node Version Manager (NVM). With it, you can easily switch back and forth between versions.
The solution provided by phucanhapril on May 24, 2017 in this thread worked for me.
To summarise, edit ~/.profile and change your PATH to this:
PATH="$HOME/bin:$HOME/.local/bin:/usr/bin:$PATH"
(By default it does not include /usr/bin)
Then run:
source ~/.profile
I am not quite sure why npm doesn't work properly in the first place, or why /usr/bin isn't in PATH by default, but the solution worked for me.
I had the same problem to solve I installed "NVM" in my Subsystem
Follow these steps and see if it will solve for you:
sudo apt-get update
sudo apt-get install build-essential libssl-dev
curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh -o install_nvm.sh
bash install_nvm.sh
source ~/.profile
nvm install 11.13.0
You can try sudo npm install it was a solution in my particular case.
Linux command for install nodejs and npm
sudo apt-get install nodejs
sudo apt-get install npm
Set path in linux
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
reference
https://github.com/microsoft/WSL/issues/3882
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs
this is enough, if you still face the problem
node installation needs restart, close you ubuntu window and start again it will solve your problem :)
I had the same problem. This is what I did.
Step 1. Type node -v and npm -v commands in Windows PowerShell and check if node and npm are properly installed
Step 2. Add this to the ~/.zshrc or ~/.bashrc file
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
Step 3. Type source ~/.zshrc and/or source ~/.bashrc
Step 4. Type node -v and npm -v commands in bash or zsh shells and the correct versions should now appear
On Visual Studio -> Tools -> Options -> Projects and Solutions -> Web Package Management -> make sure $(PATH) is above all the rest.
As long it is not located at the top of the list VS will try to use VS tools instead of npm.
You should also refer windows to the current npm version by following this screenshot, after try npm --version.
Changing npm path:
I had this issue in both Debian and Ubuntu (though in Ubuntu the nvm command did work) when I was running Windows 10 version 1703. Then when I upgraded to version 1903 the problem disappeared.
I had the same error and it may seem silly, but I fixed it by simply typing exit in the console and opening it again.
I received this error when I modified my "~/.bashrc" file to shorten up the bash directory.
At first I had:
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u\h:\W\$'
fi
....But then could not run any node operation. I rolled it back and the error stopped happening.
After some troubleshooting, I was able to fix the error by adding ~ before the $ on PS1='${debian_chroot:+($debian_chroot)}\u\h:\W\~$
I just read through many threads trying to do this. There is complete documentation for setting up node, nvm, and npm in wsl, here: https://learn.microsoft.com/en-us/windows/nodejs/setup-on-wsl2
If you already installed node and npm using the following commands,
sudo apt-get install nodejs
sudo apt-get install npm
NPM will not work. You must first uninstall them using:
sudo apt-get remove nodejs
sudo apt-get remove npm
Follow the guide to completely uninstalling here: How can I completely uninstall nodejs, npm and node in Ubuntu
Then reinstall from the windows guide referenced above.
The windows guide has many other useful resources.
The Tldr to install(from Microsoft Docs):
sudo apt-get install curl
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
nvm install --lts
I had identical output to that in the question. It occurs because Ubuntu on WSL adds Windows paths to the bash shell, but of course the Windows executables do not work in bash.
I installed nvm, and from there installed node into bash. NVM works out all the paths so it works.

Is NVM working on latest Windows Linux Subsystem (WSL)?

I'm able to install NVM via script and able to execute something like nvm use v6.3.1
However everytime I try to install stuff from my package.json i get permission denied errors as described here
https://github.com/Microsoft/BashOnWindows/issues/14
I tried looking online but no clear answers. Is nvm working on the latest WSL?
Is npm working ok for you?
Not sure if you error is related, but I found I had to either:
sudo apt-get install nodejs-legacy
or
sudo ln -fs /usr/bin/nodejs /usr/local/bin/node
in order to get Node to work properly.

Installation of RVM on Ubuntu Server 12.04

I am running a VM with Ubuntu Server 12.04.
I try to install a Ruby on Rails Application and first of all i needed to install Curl (which is done) and now i try to install RVM.
I am following this installation guide : ruby on rails installation
i am at the step when i have to run rvm to check. But it won't load when i try to enter :
source ~/.rvm/scripts/rvm
UPDATE :
I have this folder /usr/local/rvm
when i try to run this : rvm requirements
he says : the program 'rvm' is currently not installed....
but i did with this command :
\curl -L https://get.rvm.io | bash -s stable
as shown in the tutorial, or didn't it install ? i have no errors...
i even see : thank you for using rvm!
-sh: 1: source: not found
any ideas? i am relatively new to ubuntu. thanks in advance
as the message says:
-sh: 1: source: not found
where sh is your current shell - RVM is not compatible with it, you need to use bash:
sudo apt-get install -y bash && sudo chsh -s $(which bash)
I have not tested this steps so you might slightly adjust it for your system.
For RVM to work properly, you have to set the 'Run command as login shell' checkbox on the Title and Command tab inside of gnome-terminal's Settings page.
To do that open up a terminal by pressing CTRL+ALT+t. Once your terminal is open, right click the terminal, and click on Profiles then Profile Preferences.
Screen shot at http://rvm.io/integration/gnome-terminal