Accessing nodejs as non root - node.js

I have node 0.10.x installed via apt-get and also nvm/npm.
I used nvm to install node 0.12.7 and used this command
(n=$(which node);n=${n%/bin/node}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/local)
to copy the node binaries to /usr/local/ so that other users can use the version I chose using nvm. However getting the following error trying to do an npm install:
bash: /usr/local/bin/npm: /root/.nvm/versions/v0.12.7/bin/node: bad
interpreter: Permission denied
Any advice?

Related

Uninstalling node with homebrew [duplicate]

My version of node is always v0.6.1-pre even after I install brew node and NVM install v0.6.19.
My node version is:
node -v
v0.6.1-pre
NVM says this (after I install a version of node for the first time in one bash terminal):
nvm ls
v0.6.19
current: v0.6.19
But when I restart bash, this is what I see:
nvm ls
v0.6.19
current: v0.6.1-pre
default -> 0.6.19 (-> v0.6.19)
So where is this phantom node 0.6.1-pre version and how can I get rid of it? I'm trying to install libraries via NPM so that I can work on a project.
I tried using BREW to update before NVM, using brew update and brew install node.
I've tried deleting the "node" directory in my /usr/local/include and the "node" and "node_modules" in my /usr/local/lib.
I've tried uninstalling npm and reinstalling it following these instructions.
All of this because I was trying to update an older version of node to install the "zipstream" library. Now there's folders in my users directory, and the node version STILL isn't up to date, even though NVM says it's using 0.6.19.
Ideally, I'd like to uninstall nodejs, npm, and nvm, and just reinstall the entire thing from scratch on my system.
Apparently, there was a /Users/myusername/local folder that contained a include with node and lib with node and node_modules. How and why this was created instead of in my /usr/local folder, I do not know.
Deleting these local references fixed the phantom v0.6.1-pre. If anyone has an explanation, I'll choose that as the correct answer.
EDIT:
You may need to do the additional instructions as well:
sudo rm -rf /usr/local/{lib/node{,/.npm,_modules},bin,share/man}/{npm*,node*,man1/node*}
which is the equivalent of (same as above)...
sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node* /usr/local/lib/dtrace/node.d ~/.npm ~/.node-gyp
or (same as above) broken down...
To completely uninstall node + npm is to do the following:
go to /usr/local/lib and delete any node and node_modules
go to /usr/local/include and delete any node and node_modules directory
if you installed with brew install node, then run brew uninstall node in your terminal
check your Home directory for any local or lib or include folders, and delete any node or node_modules from there
go to /usr/local/bin and delete any node executable
You may also need to do:
sudo rm -rf /opt/local/bin/node /opt/local/include/node /opt/local/lib/node_modules
sudo rm -rf /usr/local/bin/npm /usr/local/share/man/man1/node.1 /usr/local/lib/dtrace/node.d
Additionally, NVM modifies the PATH variable in $HOME/.bashrc, which must be reverted manually.
Then download nvm and follow the instructions to install node. The latest versions of node come with npm, I believe, but you can also reinstall that as well.
For brew users, OSX:
To remove:
brew uninstall node;
# or `brew uninstall --force node` which removes all versions
brew cleanup;
rm -f /usr/local/bin/npm /usr/local/lib/dtrace/node.d;
rm -rf ~/.npm;
To install:
brew install node;
which node # => /usr/local/bin/node
export NODE_PATH='/usr/local/lib/node_modules' # <--- add this ~/.bashrc
You can run brew info node for more details regarding your node installs.
consider using NVM instead of brew
NVM (node version manager) is a portable solution for managing multiple versions of node
https://github.com/nvm-sh/nvm
> nvm uninstall v4.1.0
> nvm install v8.1.2
> nvm use v8.1.2
> nvm list
v4.2.0
v5.8.0
v6.11.0
-> v8.1.2
system
you can use this with AVN to automatically switch versions as you hop between different projects with different node dependencies.
UPDATE: 23 SEP 2016 - Intel Macs 10.11.x and above
If you're afraid of running these commands...
Thanks to jguix for this quick tutorial.
First, create an intermediate file:
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.node.pkg.bom >> ~/filelist.txt
Manually review your file (located in your home ~ folder)
~/filelist.txt
Then delete the files:
cat ~/filelist.txt | while read f; do sudo rm /usr/local/${f}; done
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
Intel Macs 10.10.x and below
Thanks Lenar Hoyt
Gist Comment Source: gistcomment-1572198
Original Gist: TonyMtz/d75101d9bdf764c890ef
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.node.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
ORIGINAL: 7 JUL 2014
I know this post is a little dated but just wanted to share the commands that worked for me in Terminal when removing Node.js.
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
On Mavericks I install it from the node pkg (from nodejs site) and I uninstall it so I can re-install using brew. I only run 4 commands in the terminal:
sudo rm -rf /usr/local/lib/node_modules/npm/
brew uninstall node
brew doctor
brew cleanup --prune-prefix
If there is still a node installation, repeat step 2. After all is ok, I install using brew install node
https://stackabuse.com/how-to-uninstall-node-js-from-mac-osx/
Run following commands to remove node completely from system in MACOS
sudo rm -rf ~/.npm ~/.nvm ~/node_modules ~/.node-gyp ~/.npmrc ~/.node_repl_history
sudo rm -rf /usr/local/bin/npm /usr/local/bin/node-debug /usr/local/bin/node /usr/local/bin/node-gyp
sudo rm -rf /usr/local/share/man/man1/node* /usr/local/share/man/man1/npm*
sudo rm -rf /usr/local/include/node /usr/local/include/node_modules
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /usr/local/lib/dtrace/node.d
sudo rm -rf /opt/local/include/node /opt/local/bin/node /opt/local/lib/node
sudo rm -rf /usr/local/share/doc/node
sudo rm -rf /usr/local/share/systemtap/tapset/node.stp
brew uninstall node
brew doctor
brew cleanup --prune-prefix
After this I will suggest to use following command to install node using nvm (check https://github.com/nvm-sh/nvm for latest version)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
from https://github.com/nvm-sh/nvm
Why nvm?
this is a good question, there will be projects requiring different versions of node, i.e. A requires node version 12 while B requires node version 14. This version management of node is provided by nvm only.
I have summarized the existing answers and made sure Node.js is COMPLETELY ERASED along with NPM.
Lines to copy to terminal:
brew uninstall node;
which node;
sudo rm -rf /usr/local/bin/node;
sudo rm -rf /usr/local/lib/node_modules/npm/;
brew doctor;
brew cleanup --prune-prefix;
First:
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
To recap, the best way (I've found) to completely uninstall node + npm is to do the following:
go to /usr/local/lib and delete any node and node_modules
cd /usr/local/lib
sudo rm -rf node*
go to /usr/local/include and delete any node and node_modules directory
cd /usr/local/include
sudo rm -rf node*
if you installed with brew install node, then run brew uninstall node in your terminal
brew uninstall node
check your Home directory for any "local" or "lib" or "include" folders, and delete any "node" or "node_modules" from there
go to /usr/local/bin and delete any node executable
cd /usr/local/bin
sudo rm -rf /usr/local/bin/npm
ls -las
You may need to do the additional instructions as well:
sudo rm -rf /usr/local/share/man/man1/node.1
sudo rm -rf /usr/local/lib/dtrace/node.d
sudo rm -rf ~/.npm
Source: tonyMtz
downgrade node to 0.10.36
sudo npm cache clean -f
sudo npm install -g n
sudo n 0.10.36
upgrade node to stable v
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
I'm not sure if it's because I had an old version (4.4.5), or if it's because I used the official installer, but most of the files referenced in other answers didn't exist on my system. I only had to remove the following:
~/.node-gyp
~/.node_repl_history
/usr/local/bin/node
/usr/local/bin/npm
/usr/local/include/node
/usr/local/lib/dtrace/node.d
/usr/local/lib/node_modules
/usr/local/share/doc/node
/usr/local/share/man/man1/node.1
/usr/local/share/systemtap/tapset/node.stp
I decided to keep ~/.npm because I was planning on reinstalling Node with Homebrew.
Complete uninstall Node.js on macOS Monterey version 12.0.1
To check the current node version installed on your system:
# node -v
# v14.15.0
Enter the given below commands to delete Node from your system:
# cd /usr/local/include
# sudo rm -R node
# cd ../lib
# sudo rm -R node_modules
# cd ../bin
# sudo rm -R node
to check that node doesn't exist anymore
# node -v
# -bash: node: command not found
Install Node.js on macOS Monterey version 12.0.1
Download the LTS version of node from the official website
Double click on the node-v16.13.1.pkg installation package and continue with the default settings
Type node -v in your terminal to print the current installed version of node : v16.13.1 & npm -v to print the current npm version installed on your machine : 8.1.2
Complete uninstall Nodejs on macOS Big Sur version 11.2.3 (20D91)
Introduction
First things first, I want to say thank you for sharing this trick #tonymtz.
My system is running macOS Big Sur version 11.2.3 (20D91) with nodejs Latest Current Version: 15.14.0 (includes npm 7.7.6) installed from the official website.
I tried to fully uninstall nodejs on my MacBook Pro in order to re-install it with homebrew package manager using:
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
but I was facing an issue like #AhteshamShah mentioned in #JohelAlvarez's answer:
When fired first command getting: can't open /var/db/receipts/org.nodejs.pkg.bom: No such file or directory **** Can't open /var/db/receipts/org.nodejs.pkg.bom.
– Ahtesham Shah Jun 20 '19 at 5:09
I dived into the original post linked by #JohelAlvarez, reading all the comments and I've found this comment from #e2tha-e:
#tonymtz On my installation of Node v4.0.0 on Yosemite 10.10.5, the first line needed to be
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.node.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
A different filename from org.nodejs.pkg.bom
Otherwise, this worked like a charm!
#e2tha-e was right, on macOS Big Sur version 11.2.3 (20D91) with nodejs Latest Current Version: 15.14.0 (includes npm 7.7.6) installed from official website, the file name is not org.nodejs.pkg.bom but org.nodejs.node.pkg.bom .
You can check this when you cd /var/db/receipts/ && ls -la.
Solution for installation from Nodejs's official website
With your preferred Terminal, fully uninstall Nodejs from your system like this :
Option 1
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.node.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
Option 2
Go to /var/db/receipts/ and delete any org.nodejs.*
cd /var/db/receipts/ && ls -la
sudo rm -rf org.nodejs.*
Go to /usr/local/lib and delete any node and node_modules
cd /usr/local/lib && ls -la
sudo rm -rf node*
Go to /usr/local/include and delete any node and node_modules directory
cd /usr/local/include && ls -la
sudo rm -rf node*
Check your $HOME directory for any "local" or "lib" or "include" folders, and delete any "node" or "node_modules" from there.
Go to /usr/local/bin and delete any node executable
cd /usr/local/bin && ls -la
sudo rm -rf /usr/local/bin/npm
sudo rm -rf /usr/local/bin/node
You may need to do this too:
sudo rm -rf /usr/local/share/man/man1/node.1
sudo rm -rf /usr/local/lib/dtrace/node.d
sudo rm -rf ~/.npm
After that, you can check if there is still node in your system with which node or find all occurrences for node in your system.
Tips
Search where node files are with find / -name 'node' | sed -E 's|/[^/]+$||' |sort -u
Before running shared code by others, check your directories before to make sure you write the right file name.
Steps to Uninstall NodeJS:
For MacOS Monterey with M1 chip, please follow the link below to uninstall node completely from the system. I have tried multiple ways but this one worked finally.
Uninstall NodeJS & NPM from Mac M1 Monterey
Additionally, please execute the following commands at the end to remove node related directories from bin folder.
sudo rm -R node-sass
sudo rm -R npm
sudo rm -R npx
To verify that node is removed:
node --version
It should say command not found.
Steps to Install NodeJS:
Enable Rosseta terminal on your Mac with M1 chip.
How to enable Rosseta terminal
Use nvm (Node Version Manager) to install NodeJS on your machine. Why nvm?? Because you can run multiple versions of NodeJS (you can work with a new app as well as a Legacy app).
How to install multiple versions of NodeJS using nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Create a .zshrc file if not exists.
touch ~/.zshrc
Install node using nvm.
nvm install node # "node" is an alias for the latest version
nvm install 14.7.0 # or 16.3.0, 12.22.1, etc
To verify the number of NodeJS versions available:
nvm ls
After
brew uninstall node
I had to know which node
which node
then remove that
rm -rf /usr/local/bin/node
Delete node and/or node_modules from /usr/local/lib
ex code:
cd /usr/local/lib
sudo rm -rf node
sudo rm -rf node_modules
Delete node and/or node_modules from /usr/local/include
Delete node, node-debug, and node-gyp from /usr/local/bin
Delete .npmrc from your home directory (these are your npm settings, don't delete this if you plan on re-installing Node right away)
Delete .npm from your home directory
Delete .node-gyp from your home directory
Delete .node_repl_history from your home directory
Delete node* from /usr/local/share/man/man1/
Delete npm* from /usr/local/share/man/man1/
Delete node.d from /usr/local/lib/dtrace/
Delete node from /usr/local/opt/local/bin/
Delete node from /usr/local/opt/local/include/
Delete node_modules from /usr/local/opt/local/lib/
Delete node from /usr/local/share/doc/
Delete node.stp from /usr/local/share/systemtap/tapset/
Worked for me.
$node --version
v11.1.0
$nvm deactivate
$nvm uninstall v11.1.0
If you have already installed nvm then execute the following commands
nvm deactivate - This will remove /.nvm/*/bin from $PATH
nvm list - To list out all the versions of node installed in the system
nvm uninstall <version> in you can specify all the versions you want to uninstall.
It is always a good that you install node using nvm and uninstall using nvm
rather than brew .
This solution worked for me.
Additional Commands
which node to know the path of node installed in your system. You can rm this directory to uninstall node manually. Then you may need to adjust the PATH file accordingly.
Expanding on Dominic Tancredi's awesome answer, I've rolled this into a bash package and stand-alone script. If you are already using the "Back Package Manager" called bpkg you can install the script by running:
bpkg install -g brock/node-reinstall
Or you can have a look at the script on Github at brock/node-reinstall. The script allows you to re-install node using nvm or nave, and to specify a node version as your default.
Additional to the main answer I needed to remove all npm instances found in:
rm -rf /usr/local/share/man/man1/npm*
maybe you need to make
hash -r
it helps with problem of symlink
$ node -v
$ bash: /opt/local/bin/node: No such file or directory
The best way is to download an installer package: .pkg on mac. Prefer the latest stable version.
Here is the link: Node.js
This package will eventually overwrite the previous version and set environment variables accordingly. Just run the installer and its done within a few clicks.
I have been hit by an issue during uninstall of Node.js on my mac. I had some strange behavior like npm is still there even after having to remove it with all this.
It was because I had an old install done with macport. So you also have to uninstall it using port:
sudo port uninstall nodejs
It may have installed many different versions of Node.js so uninstall them all (one by one).
You can clone https://github.com/brock/node-reinstall and run the simple command as given in the repository.After that just restart your system.
This is the simplest method and also worked for me.
I had installed Node.js from source downloaded from the git repository. I installed with:
./configure
$ make
$ sudo make install
Because the make file supports it, I can do:
$ sudo make uninstall
As a companion to the answers explaining cleanup and install via homebrew, I found that homebrew itself provided clear indications of the symlink clashes.
Unfortunately it provides these one by one as it encounters them, so it is a little laborious, but it does seem to find all the clashes and was the only way I could get a clean install with homebrew.
Essentially, the process is:
use homebrew to uninstall node
clean homebrew
use homebrew to install node and note any flagged clashing file
delete the flag clashing file (or whole directory if it is a 'node' directory)
goto step 1 until you get a clean install
:
Here is a screen output from the last steps of my install - you can see it results in a clean install (eventually...):
computer1:DevResources user1$ brew install node
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/node-13.1.0.mojave.bottle.tar.gz
Already downloaded: /Users/user1/Library/Caches/Homebrew/downloads/da904f1fdab6f6b2243a810b685e67b29a642c6e945f086e0022323a37fe85f9--node-13.1.0.mojave.bottle.tar.gz
==> Pouring node-13.1.0.mojave.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink share/systemtap/tapset/node.stp
Target /usr/local/share/systemtap/tapset/node.stp
already exists. You may want to remove it:
rm '/usr/local/share/systemtap/tapset/node.stp'
To force the link and overwrite all conflicting files:
brew link --overwrite node
To list all files that would be deleted:
brew link --overwrite --dry-run node
Possible conflicting files are:
/usr/local/share/systemtap/tapset/node.stp
/usr/local/lib/dtrace/node.d
==> Caveats
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
==> Summary
🍺 /usr/local/Cellar/node/13.1.0: 4,591 files, 54.2MB
computer1:DevResources user1$ rm '/usr/local/share/systemtap/tapset/node.stp'
computer1:DevResources user1$ brew uninstall node
Uninstalling /usr/local/Cellar/node/13.1.0... (4,591 files, 54.2MB)
computer1:DevResources user1$ brew cleanup
computer1:DevResources user1$ brew install node
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/node-13.1.0.mojave.bottle.tar.gz
Already downloaded: /Users/user1/Library/Caches/Homebrew/downloads/da904f1fdab6f6b2243a810b685e67b29a642c6e945f086e0022323a37fe85f9--node-13.1.0.mojave.bottle.tar.gz
==> Pouring node-13.1.0.mojave.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink lib/dtrace/node.d
Target /usr/local/lib/dtrace/node.d
already exists. You may want to remove it:
rm '/usr/local/lib/dtrace/node.d'
To force the link and overwrite all conflicting files:
brew link --overwrite node
To list all files that would be deleted:
brew link --overwrite --dry-run node
Possible conflicting files are:
/usr/local/lib/dtrace/node.d
==> Caveats
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
==> Summary
🍺 /usr/local/Cellar/node/13.1.0: 4,591 files, 54.2MB
computer1:DevResources user1$ rm '/usr/local/lib/dtrace/node.d'
computer1:DevResources user1$
computer1:DevResources user1$ brew uninstall node
Uninstalling /usr/local/Cellar/node/13.1.0... (4,591 files, 54.2MB)
computer1:DevResources user1$ brew cleanup
computer1:DevResources user1$ brew install node
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/node-13.1.0.mojave.bottle.tar.gz
Already downloaded: /Users/user1/Library/Caches/Homebrew/downloads/da904f1fdab6f6b2243a810b685e67b29a642c6e945f086e0022323a37fe85f9--node-13.1.0.mojave.bottle.tar.gz
==> Pouring node-13.1.0.mojave.bottle.tar.gz
==> Caveats
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
==> Summary
🍺 /usr/local/Cellar/node/13.1.0: 4,591 files, 54.2MB
computer1:DevResources user1$ node -v
v13.1.0
First of all, you need to deactivate node: (mac) after install new node version.
nvm deactivate
This is removed /Users/user_name/.nvm/*/bin from $PATH
And after that node was updated
node --version
v10.9.0
In my case none of the other answers worked because I previously downgraded to node8. So instead of doing above, following worked for me:
which node
which returned /usr/local/bin/node#8 instead of /usr/local/bin/node
so i executed this command:
brew uninstall node#8
which worked and then downloaded latest pkg from official site and installed. After that I had to close my terminal and start again to access new version
Docker - alternative approach
Docker is some-kind of super-fast virtual machine which can be use to run tools like node (instead install them directly on mac-os). Advantages to do it are following
all stuff ('milions' node files) are install inside docker image/container (they encapsulated in few inner-docker files)
you can map your mac directory with project to your docker container and have access to node - but outside docker, mac-os sytem don't even know that node is installed. So you get some kind of 'virtual' console with available node commands which can works on real files
you can easily kill node by find it by docker ps and kill by docker rm -f name_or_num
you can easily uninstall docker image/containers by one command docker rmi ... and get free space - and install it again by run script (below)
your node is encapsulated inside docker and don't have access to whole system - only to folders you map to it
you can run node services and easily map they port to mac port and have access to it from web browser
you can run many node versions at the same time
in similar way you can install other tools like (in many versions in same time): php, databases, redis etc. - inside docker without any interaction with mac-os (which not notice such software at all). E.g. you can run at the same time 3 mysql db with different versions and 3 php application with different php version ... - so you can have many tools but clean system
TEAM WORK: such enviroment can be easily cloned into other machines (and even to windows/linux systems - with some modifications) and provide identical docker-level environment - so you can easily set up and reuse you scripts/dockerfiles, and setup environment for new team member in very fast way (he just need to install docker and create similar folder-structure and get copy of scripts - thats all). I work this way for 2 year and with my team - and we are very happy
Instruction
Install docker using e.g. this instructions
Prepare 'special' directory for work e.g. my directory is /Users/kamil/work (I will use this directory further - but it can be arbitrary) - this directory will be 'interface' between docker containers and your mac file ststem. Inside this dir create following dir structure:
/Users/kamil/work/code - here you put your projects with code
/Users/kamil/work/tools
/Users/kamil/work/tools/docker-data - here we map containers output data like logs (or database files if someone ouse db etc.)
/Users/kamil/work/tools/docker
/Users/kamil/work/tools/docker/node-cmd - here we put docker node scripts
inside tools create file .env which will contain in one place global-paths used in other scripts
toolspath="/Users/kamil/work/tools"
codepath="/Users/kamil/work/code"
workpath=/Users/kamil/work
innside dir ../node-cmd create file dockerfile with following content
# default /var/www/html (mapped to .../code folder with projects)
FROM node
WORKDIR /work
# Additional arbitrary tools (ng, gulp, bower)
RUN npm install -g n #angular/cli bower gulp grunt
CMD while true; do sleep 10000; done
# below ports are arbitrary
EXPOSE 3002 3003 3004 4200
innside dir ../node-cmd create file run-container with following content (this file should be executable e.g. by chmod +x run-container) - (notice how we map port-s and directories form external 'world' to internal docker filesystem)
set -e
cd -- "$(dirname "$0")" # this script dir (not set on doubleclick)
source ../../.env
toolsdir=$toolspath/docker-data
workdir=$workpath
if [ ! "$(docker ps | grep node-cmd)" ]
then
docker build -t node-cmd .
docker rm -f node-cmd |:
docker run -d --name node-cmd -p 4200:4200 -p 4201:4201 -p 3002:3002 -p 3003:3003 -p 3004:3004 -v $toolsdir/node-cmd/logs:/root/.npm/_logs -v $workdir:/work node-cmd
fi
ok now you can add some project e.g. work/code/myProject and add to it following file 'run-cmd' (must be executable)
cd -- "$(dirname "$0")"
../../tools/docker/node-cmd/run-container
docker exec -it node-cmd bash -c "cd /work/code/myProject; bash"
then if you run above script (by double-click), you will see console with available node commands in project directory e.g. npm install
to run project in background (e.g some serwice) e.g. run web-server angular-cli application you can use following script (named run-front -must be executable) - (you must also edit /etc/hosts file to add proper domain)
cd -- "$(dirname "$0")"
open "http://my-angular.local:3002"
../../tools/docker/node-cmd/run-container
docker exec -it node-cmd /bin/sh -c "cd /work/code/my-angular-project; npm start"
cat # for block script and wait for user ctrl+C
If you're unable to locate node just run whereis node and whereis npm and whereis nvm and you can remove the listed directories as needed.
You'll also need to entirely close your terminal and reopen it for changes to take effect.
This fixed it for me Fixing npm On Mac OS X for Homebrew Users. And it does not require too many steps.
Just go to the solution part if you don't care about the why.
Here is the relevant part for convenience:
Solution
This solution fixes the error caused by trying to run npm update npm -g. Once you're finished, you also won't need to use sudo to install npm modules globally.
Before you start, make a note of any globally installed npm packages. These instructions will have you remove all of those packages. After you're finished you'll need to re-install them.
Run the following commands to remove all existing global npm modules, uninstall node & npm, re-install node with the correct defaults, configure the location for global npm modules to be installed, and then install npm as its own package.
rm -rf /usr/local/lib/node_modules
brew uninstall node
brew install node --without-npm
echo prefix=~/.npm-packages >> ~/.npmrc
curl -L https://www.npmjs.com/install.sh | sh
Node and npm should be correctly installed at this point. The final step is to add ~/.npm-packages/bin to your PATH so npm and global npm packages are usable. To do this, add the following line to your ~/.bash_profile:
export PATH="$HOME/.npm-packages/bin:$PATH"
Now you can re-install any global npm packages you need without any problems.
#lfender6445 answer worked just fine for me to uninstall
Now to re-install, I had problems installing the last version instead of the most stable one, so to install a specific node version you should do:
brew install node#10 // 10 is the version I want
brew link node#10

Installation Node v4.1 with NVM - Permission denied

I have to install Node v4.1.x on Ubuntu. I have already installed it but with the wrong version. This are the steps that I followed untill now:
Installation of nvm
sudo git clone https://github.com/creationix/nvm.git /opt/nvm
sudo mkdir /usr/local/nvm
sudo addgroup -system dev
sudo chown -R root:dev /usr/local/nvm
sudo chmod -R 775 /usr/local/nvm
sudo vim /etc/profile.d/nvm.sh
Editing of the file
export NVM_DIR=/usr/local/nvm
source /opt/nvm/nvm.sh
export NPM_CONFIG_PREFIX=/usr/local/node
export PATH="/usr/local/node/bin:$PATH"
Installation of Node
sudo mkdir /usr/local/node
sudo chown -R root:dev /usr/local/node
sudo chmod -R 775 /usr/local/node
nvm stable
For installing node v4.1.x this is what I want to do:
nvm ls //list of all version
nvm use 4.1.x //if I find the correct version in the list
The problem is that I can't make nvm ls because I get
mkdir: cannot create directory ‘/usr/local/nvm/alias’: Permission denied
What can I do?
I think you might change NVM_DIR to:
NVM_DIR="$HOME/.nvm"
The problem is that you've installed nvm using root user (with sudo). When executing nvm commands later:
nvm ls
nvm use 4.1.x
you do this without root and you get a permission denied.
Generally it is not recommended to install nvm using super user.
Please check this article for more details on how to install the version manager: http://rainsoft.io/install-node-like-a-boss-with-nvm/
This can also be because of issues during the curl installation.
Try reinstalling using
sudo apt-get install build-essential libssl-dev curl git-core
In your case issue because you gave 755 permission to the nvm folder. So it cant create folder without write permission as non root user.
Solution is you should be a root user or else give write permission for the folder to your particular user.
I too faced the same issue while installing nvm
ubuntu#ip-10-0-0-94:~$ nvm install 6.0.0
It reported as,
nvm install 6.0.0 mkdir: cannot create directory ‘/home/ubuntu/.nvm/bin’: Permission denied
grep: /home/ubuntu/.nvm/bin/node-v6.0.0-linux-x64/node-v6.0.0-linux-x64.tar.xz: No such file or directory Binary download failed
It with the 755 permission before.
drwxr-xr-x 4 root root 4096 Jun 23 07:44 .nvm/
Then I just gave write permission for it.
sudo chmod +w .nvm
Now issue was resolved and working fine.
ubuntu#ip-10-0-0-94:~$ nvm install 6.0.0
Downloading https://nodejs.org/dist/v6.0.0/node-v6.0.0-linux-x64.tar.xz...
######################################################################## 100.0%

Unable to install global modules using sudo npm

I was trying to install pm2, sails.js for Node.js from a non-root user with sudo. I get the below error:
sudo npm install pm2 -g
sudo: npm: command not found
but when i try to install using the below command, it works
sudo /usr/local/bin/npm install pm2 -g
How can i make sudo npm work?
Thanks.
How i installed Node and npm with su previously:
su -
yum install gcc-c++ openssl-devel python
cd /usr/local/src
wget http://nodejs.org/dist/node-latest.tar.gz
tar zxvf node-latest.tar.gz
(cd into extracted folder: ex "cd node-v0.10.3")
./configure
make
make install
It means the npm is not install with sudo, so it is not in the path of root. I think, it is better to always use npm without 'sudo'. Because you can keep the packaged installed with npm in your local environment.
If you really want to use with sudo, you can re-install node with sudo.
Yes, NPM is not installed on your system.
you can check first if node is set perfectly.
$node -v
it will give version.
if yes then check
$npm -v
if its not giving version may be your environment path is not set then execute
$PATH=/usr/bin/node:$PATH
and just check node -v and npm -v . if npm gives version number. thats it. It will install global package.
A big thanks to everyone who helped me out! Just like #Rodrigo Medeiros advised me, i installed node.js and npm using the below method taken from (https://gist.github.com/isaacs/579814#file-take-ownership-sh) but modified two lines of commands as per the advise from a comment posted by deesejohn in that page.
cd
sudo yum install gcc-c++
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=$HOME/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl -L https://www.npmjs.org/install.sh | sh
Check installed version using node -v and npm -v
Now, i am able to install npm modules globally without sudo permissions, there are many ways to install node.js and npm but this worked for me.
Thanks.

Why does node is not available to all users with NVM?

It's probably a newbie question but I'm wondering why when I install node with nvm, it is only available for this user (it's not "global").
Let's say I'm log into the server with a user "admin":
curl https://raw.githubusercontent.com/creationix/nvm/v0.7.0/install.sh | sh
source ~/.profile
nvm install 0.10.30
nvm use 0.10.30
node -v
# outputs v0.10.30
Node is up and running for this user but when I switch to the root:
su
node -v
It displays:
The program 'node' can be found in the following packages:
* node
* nodejs-legacy
Try: apt-get install <selected package>
Why that? Is there a way to install node and make it available to all users? (I don't want to reinstall every time I need it for a new user.)
The problem is that NVM installs node.js to a user's local directory, and updates that user's .profile.
Here's a one line script that can copy your install to /usr/local/bin, where everybody can use node.js:
https://www.digitalocean.com/community/tutorials/how-to-install-node-js-with-nvm-node-version-manager-on-a-vps
n=$(which node);n=${n%/bin/node}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/local

On EC2: sudo node command not found, but node without sudo is ok

I have just installed nodejs on a new EC2 micro instance.
I installed it normally, ./configure -> make -> sudo make install.
Problem: When I run "node" under ec2-user, it runs perfectly. When I run "sudo node", it fails.
I found out that node is in:
[ec2-user#XXXX ~]$ whereis node
node: /usr/local/bin/node /usr/local/lib/node
and the current path is
[ec2-user#XXXX ~]$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/opt/aws/bin:/home/ec2-user/bin
but, the sudo path is
[root#ip-10-112-222-32 ~]# echo $PATH
/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin:/root/bin
then I tried to edit the root PATH to include the paths to node, so "node" runs when I'm logged in as root - but it still won't work when I log in as ec2-user and run "sudo node".
I need this to install npm properfly. Any idea on how to include the node path while running "sudo node"?
Yes, it is a bit annoying but you can fix it with some links:
sudo ln -s /usr/local/bin/node /usr/bin/node
sudo ln -s /usr/local/lib/node /usr/lib/node
sudo ln -s /usr/local/bin/npm /usr/bin/npm
sudo ln -s /usr/local/bin/node-waf /usr/bin/node-waf
There might be more but that is all I have run across so far. Lack of node-waf will cause some npm installs to fail with a rather cryptic error message.
I added /usr/local/bin to secure_path in /etc/sudoers
$ sudo visudo
Then change this line:
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin
To:
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
it happens because the node executable is not found in /usr/bin. So follow the steps:
find node:
whereis node
in my case: node: /home/<my_user>/.nvm/versions/node/v8.9.4/bin/node
make a symbolic link for node:
sudo ln -s /home/<my_user>/.nvm/versions/node/v8.9.4/bin/node /usr/bin/node
It's done!
Why not use the absolute path to node? If you planning to use an upstart script it is going to need an absolute path anyways.
sudo /usr/local/bin/node server.js
try the following:
export PATH=$PATH:/usr/local/bin
sudo node --version
You could pass full path to node executable from parent (non-sudo shell) using which command.
sudo `which node`
For me, it worked to just change ownership of node folder from root to ec2-user (logged in as ec2-user).
(Note: I created my node folder in /var/lib/)
sudo chown -R ec2-user /var/lib/node/
Then
npm install mongojs
should work fine (provided you have installed npm ok of course!)
How about using "sudo $(which node)" instead of "sudo node" ?
Here's an approach that doesn't use symlinks, or require root:
$ git clone https://github.com/joyent/node.git
$ cd node
$ mkdir ~/opt
$ export PREFIX=~/opt; ./configure
$ make
$ make install
$ echo 'export PATH=~/opt/bin:${PATH}' >> ~/.bashrc
Then I did:
$ git clone https://github.com/isaacs/npm.git
$ cd npm
$ make install
The benefits of not running node as root are discussed here:
http://increaseyourgeek.wordpress.com/2010/08/18/install-node-js-without-using-sudo/
Its inline with:
https://github.com/joyent/node/wiki/Installation
In my case, Node was installed without sudo prefix. So node was unavailable for the superuser that why it is not working sudo node server
Enter as root with
sudo su
and then do standard steps
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
. ~/.nvm/nvm.sh
nvm install node
node -e "console.log('Running Node.js ' + process.version)"
This is what I did to solve a similar issue. Note: I had installed node via snap.
Step 1: Install node via snap
sudo snap install node --classic
Step 2: Find where node has been installed
whereis node
In my case
/snap/bin/node.npm
/snap/bin/node.npx
/snap/bin/node.yarn
/snap/bin/node
/snap/bin/node.yarnpkg
Step 3: Create symbolic links to node, npm, npx and yarn
sudo ln -s /snap/bin/yarn /usr/bin/yarn
sudo ln -s /snap/bin/node /usr/bin/node
sudo ln -s /snap/bin/npm /usr/bin/npm
Finally node is accessible for all users, even sudo group
sudo node
I tried everything mentioned in the above answers but nothing worked. Probably because of my lack of understanding of concepts related to sym links. I fixed the issue by not using nvm.
I just created a new ec2 instance and didn't install nvm. Instead I installed node and npm like so:
sudo apt update
sudo apt install nodejs npm
And this did it for me.
If you have installed node environment already, paste these command in you r instance and it'll link your node to your user directory. And you will be able to use node with sudo.
sudo ln -s "$(which node)" "/usr/local/bin/node"
sudo ln -s "$(which npm)" "/usr/local/bin/npm"
I don't know if this is the right way, but this is what i did...
sudo su
export PATH=$PATH:/home/ec2-user/local/node/bin
curl http://npmjs.org/install.sh | sh
chown -R ec2-user /home/ec2-user/local/node
exit
This installed npm, and I can now install any packages I want.

Resources