Related
I just installed Linux Mint (version 17.2) and I'm trying to install Ember. Everything seemed to go fine, but I'm getting this error when I run ember new testProject.
create vendor/.gitkeep
EACCES, mkdir '/home/mkm/.npm/mkdirp/0.4.2'
Error: EACCES, mkdir '/home/mkm/.npm/mkdirp/0.4.2'
at Error (native)
Per a recommendation in the Ember Documentation I used this guide to install Node.js and NPM. Some of what I've read suggest the issue is nodejs was installed with sudo, but apt-get failed when I didn't use sudo.
I attempted to run the new project anyway. bower install completed successfully. But ember serve failed with Cannot find module 'chalk'.
--Version Info
$ ember --version
version: 1.13.8
Could not find watchman, falling back to NodeWatcher for file system events.
Visit http://www.ember-cli.com/user-guide/#watchman for more info.
node: 0.12.7
npm: 2.13.4
os: linux x64
The only command that was needed to run with sudo for me was:
npm install
I suggest you delete node_modules/ in your project directory completely, then run:
sudo npm install
You can also add option --verbose to see if everything is correctly installing and installation isn't stuck.
You could also change permissions for .npm directory to avoid some problems like that in future:
sudo chmod 777 -R /home/mkm/.npm
You can use following commands to install and use npm without sudo:
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | NVM_DIR="/home/your-user-name/.nvm" bash
export NVM_DIR="/home/your-user-name/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
nvm install 0.12
nvm alias default 0.12
npm install -g ember-cli
npm install -g bower
npm install -g phantomjs
Here is a link to nvm repository with latest version and documentation: https://github.com/creationix/nvm
I installed Node.js with these instructions and it seemed successful:
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
Then I installed npm with these instructions:
sudo curl https://www.npmjs.org/install.sh | sh
The nodejs installation seemed to work without errors but the npm command gave me a lot of errors. But it seems like they are installed because when I test what version I have they both come up:
nodejs -v
v0.10.30
npm -v
1.4.21
So If this doesn't tell me that I have both programs successfully installed, which I assume I do not, how do I know?
I think your tests tell that both or properly installed.
But you can try just type node in terminal & it should open a node shell, where you can check by running basic commands.
Current distributions of node.js (including the one you downloaded) already include npm. So maybe installing npm manually is one source of your errors. Beware that usually you run "npm install" with the permissions of a regular user. There are only some npm-based utilities that are to be installed with root permissions and the '-g' (global) command line switch.
On linux if you wish to install node.js and npm as yourself NOT root :
to start fresh remove prior node.js and npm installs as well as these :
~/.npmrc
~/.npm
~/tmp
~/.npm-init.js
create your ~/bin/ directory if not already created :
mkdir ${HOME}/bin
download source from : http://nodejs.org/download/
cd node-v0.10.30/
./configure --prefix=${HOME}/bin/nodejs
make -j8
make install
which puts it into dir defined by above --prefix
export PATH=${HOME}/bin/nodejs/bin:$PATH
define NODE_PATH so node can find dir for modules otherwise
npm install xxx will put newly installed module into dir in curr dir :
export NODE_PATH=${HOME}/bin/nodejs/lib/node_modules
do above AND use syntax :
npm install xxxxx -g
always use the -g for global which puts package xxxxx into $NODE_PATH
NOTE - nodejs install gives you npm as well :
ls -la ${HOME}/bin/nodejs/bin
I have just reinstalled Ubuntu 12.04 LTS, and before anything else i did these steps:
Installed Node via package manager with the following script
sudo apt-get update
sudo apt-get install python-software-properties python g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
Tried to install yeoman, express, n, yeoman's generators globally and all of them returned the same error
npm ERR! Error: EACCES, symlink '../lib/node_modules/n/bin/n'
npm ERR! { [Error: EACCES, symlink '../lib/node_modules/n/bin/n'] errno: 3, code: 'EACCES', path: '../lib/node_modules/n/bin/n' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Linux 3.8.0-29-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "-g" "-d" "n"
npm ERR! cwd /home/heberlz
npm ERR! node -v v0.10.20
npm ERR! npm -v 1.3.11
npm ERR! path ../lib/node_modules/n/bin/n
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, symlink '../lib/node_modules/n/bin/n'
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/heberlz/npm-debug.log
npm ERR! not ok code 0
Reclaimed ownership of the following folders recursively ~/.npm, /usr/lib/node, /usr/lib/node_modules, and of the following symlinks /usr/bin/node, /usr/bin/nodejs with absolutely no success
I need to install yeoman and its generators without sudo not to be in trouble later on :(
Ubuntu 12.04 and using Chris Lea's PPA for install the following works for me:
npm config set prefix '~/.npm-packages'
and adding $HOME/.npm-packages/bin to $PATH
Append to .bashrc
export PATH="$PATH:$HOME/.npm-packages/bin"
For more see this answer from #passy
If you already have $HOME/bin in your path, a simpler solution is just ...
npm config set prefix ~
New node commands will now install into your $HOME/bin directory.
No need to change your path!
Since this discussion is really about reducing the security risks of running sudo, you should also be aware that any node app could potentially be installing an app name that does not match the registered node package name you think you're installing. So there is a security risk that an npm install will replace an existing system command or one you already have in $HOME/bin. If you're concerned, check the bin, and scripts properties in the package.json file of the app you're installing first.
In general, it's safest to:
(a) Place $HOME/bin last in your path so system commands are not superseded.
(b) don't include "." or any relative path in your $PATH so you don't accidentally run a command that happens to be in the current directory.
Reference:
package.json properties
npm install
NodeJS security vulnerabilities: nodesecurity.io.
As for October 2014:
Node.js is available from the NodeSource Debian and Ubuntu binary distributions repository.
curl -sL https://deb.nodesource.com/setup | sudo bash -
sudo apt-get install -y nodejs
That's it.
Outdated answer:
The fastest way without using sudo is like described here by isaac
I strongly encourage you not to do package management with sudo!
Packages can run arbitrary scripts, which makes sudoing a package
manager command as safe as a chainsaw haircut. Sure, it's fast and
definitely going to cut through any obstacles, but you might actually
want that obstacle to stay there.
I recommend doing this once instead:
sudo chown -R $USER /usr/local
EDIT:
There are certain security concerns and functionality limitations regarding changing the ownership of /usr/local to the current user:
if there is another user on the machine who could use global npm packages - do not change the ownership of /usr/local
https://apple.stackexchange.com/questions/1393/are-my-permissions-for-usr-local-correct
https://askubuntu.com/questions/261326/is-it-safe-to-chown-usr-local
Having said that, if you want to install global module without using sudo, I don't see any better solution (from pragmatic point of view) than mentioned. Security vs easy of use is very broad topic, and there is no easy answer for that - it just depends on your requirements.
The issue was i installed node using sudo, to avoid errors when installing npm modules globally one MUST NEVER install node with sudo.
My solution was to reinstall node it this way:
Download latest stable node sources from nodejs.org #in my case node-v0.10.20.tar.gz
tar -zxf node-v0.10.20.tar.gz #uncompress sources
cd node-v0.10.20 #enter uncompressed folder
sudo chown -R $USER /usr/local
./configure --prefix=/usr/local && make && make install
One thing to note is that only taking ownership of the /usr/local folder wouldn't work in my case because node installation itself was made with sudo
Last step to install yeoman: #although at yeoman.io it says that doing "npm install -g yo" already installs bower and grunt, there are some submodules of grunt that fail, so i fixed that by installing it by itself
npm install -g bower
npm install -g grunt
npm install -g yo
npm install -g generator-angular
I solved this problem with environment variable and shell alias:
export NPM_PREFIX=$HOME/node
alias npmg="npm -g --prefix $NPM_PREFIX"
For me npm did not honor the "prefix" config setting in .npmrc.
Find the path to npm's directory:
npm config get prefix
For many systems, this will be /usr/local.
Change the owner of npm's directories to the name of the current user (your username!):
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}
This changes the permissions of the sub-folders used by npm and some other tools (lib/node_modules, bin, and share).
Here is the link for full details
https://docs.npmjs.com/getting-started/fixing-npm-permissions
According to this similar SO post: npm throws error without sudo
Looks like you might have an ownership issue with ~/.npm directory.
As with the answer in that one, try:
sudo chown -R `whoami` ~/.npm
If you're on a developping machine, you might be better off considering using nvm.
If not, you simply want to install using your favorite package manager.
Whatever the case may be, I'd recommend checking this answer on stackoverflow
Actually, I just changed the permission of a user folder that was owned by root:
sudo chown -R $USER ~/.config/configstore
Then I could "npm install" and "bower install" without sudo!
Worked fine!
using lubuntu 14.04.3, I tried changing ownership of .npm and npm prefix, updated my path, npm installed modules to my home directory without sudo but the path was incorrect so the modules like ember were not found, linuxbew solved the problem, quick setup guide here for node/npm
This issue and other caused by the same reason can be solved installing Node in user space.
You can do it just copying and pasting in your terminal
NODEJS_ROOT=${NODEJS_ROOT:-~/nodejs}
cd /tmp
wget -N http://nodejs.org/dist/node-latest.tar.gz && tar xzf node-latest.tar.gz
NODEJS_CURRENT=$(tar tf node-latest.tar.gz|head -1)
mkdir -p $NODEJS_ROOT/$NODEJS_CURRENT
cd $NODEJS_CURRENT
./configure --prefix=$NODEJS_ROOT/$NODEJS_CURRENT && make install
cd $NODEJS_ROOT
rm current 2> /dev/null # Removes current symbolic link, if any
ln -s $NODEJS_CURRENT current
Same commands can be launched also to get Node updated to latest version.
Don't forget to edit your environment. Only once, do
echo "export NODEJS_ROOT=$NODEJS_ROOT" >> $HOME/.bash_profile
echo 'export PATH=$NODEJS_ROOT/current/bin:$PATH' >> $HOME/.bash_profile
source $HOME/.bash_profile # reload your env, so you can use node right now
Check out this article as a reabout how to Install Node.js without sudo.
For a more general solution about this topic (i.e., install software locally) see dotsoftware.
just use nvm
you will be able to dynamically switch between different node versions and it is installed locally for your user. No sudo needed. Just make sure you have fully cleaned up the old node beforehand.
https://github.com/nvm-sh/nvm
In order to install Node.js and npm locally without having to use sudo open the terminal and type:
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
wget -c http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install
wget -c https://www.npmjs.org/install.sh | sh
Use NVM
I had the same "permission denied" issue. Instead of trying to fix the NodeJS installed from https://nodejs.org/en/ which installs into folders that are owned by root instead of $USER, I used NVM. node version manager.
Install it: run curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Install a version of node: run nvm install 16
Use it:
nvm use 16
npm install -g yarn
Everything worked fine when I used Node installed by NVM.
The best solution I found was to install Node.js from the tar package on to user home directory & link the lib folder location. Here is what you need to do
This will install Nodejs under ~/.local/ instead of the default /usr/local/
Add this to your ~/.npmrc (create the file if it doesn't exist already):
root = /home/YOUR-USERNAME/.local/lib/node_modules
binroot = /home/YOUR-USERNAME/.local/bin
manroot = /home/YOUR-USERNAME/.local/share/man
Download the Nodejs source code from nodejs.org and install it under your ~/.local tree:
tar xf node......
cd node........
./configure --prefix=~/.local
make
make install
Create ~/.node_modules symlink. (This directory will be automatically searched when you load modules using require "module" in scripts. I'm not sure why Node doesn't search ~/.local/lib/node_modules by default.)
cd
ln -s .local/lib/node_modules .node_modules
Is ~/.local/bin in your path? Type
which npm
If it says ~/.local/bin/npm, you're done.
Otherwise, do this...
export PATH=$HOME/.local/bin:$PATH
...and add that line to your ~/.profile file, so it'll run every time you log in.
If you still encounter ownership or permission error while installing packages, then change ownership of ~/.local/ dir by running
chown -R user:user ~/.local/
Now you should be good to install packages via 'npm'
Note: ALL OF THE ABOVE COMMANDS ARE TO BE RUN AS USER. DO NOT USE SUDO OR ROOT LOGIN
NEVER EVER CHANGE THE PERMISSION OF FOLDERS UNDER '/USR/LIB/'. WILL LEAD TO UNSTABLE OS
I find Pawel Grzybek's explanations very convincing: They boil down to 3 simple sudo commands, never having to use sudo again for global npm installs:
sudo chown -R $(whoami) /usr/local/lib/node_modules
sudo chown -R $(whoami) /usr/local/bin
sudo chown -R $(whoami) /usr/local/share
I have the following directory structure:
/some_project
source.js
package.json
I would like to install the dependencies for some_project.
I know I could cd into some_project and then run npm install
But I was wondering if it's possible without changing the directory ?
Something like
npm install some_project/package.json
You can use the npm install <folder> variant with the --prefix option. In your scenario the folder and prefix will be the same:
npm --prefix ./some_project install ./some_project
Update: Since the --prefix option exists, I now vote for #coudy's answer to this question. Original answer below:
No, npm will always install in the current directory or, with -g, in the system wide node_modules. You can kind of accomplish this with a subshell though, which won't affect your current directory:
(cd some_project && npm install)
The parentheses makes it run in a subshell.
On windows 10 using powershell the only thing that worked for me without all the problems and edge-cases mentioned in this blog post was this
Start-Process -Wait -FilePath "npm" -ArgumentList "install" -WorkingDirectory $web_dir
Create a package.json in the root directory with the following contents:
{
"dependencies": {
"helloworldprojectname": "file:hello\\world"
}
}
Then call this to install:
npm install --prefix ./hello/world
It installs ./hello/world/node_modules using ./hello/world/package.json.
(Windows 10, Node v10.16.0, npm 7.6.1)
On Windows 10 I couldn't get --prefix to work, so I had to cd and execute it.
cd PATH_TO_FOLDER && npm install
I need to install a "global" npm applications on an offline server.
It is easy to install a normal application:
npm install
and then pack up the resulting files. Either manually or using npm pack.
However, how can I install global application (that has a install script of some sort) such as forever without Internet?
npm install -g forever
try npmbox, it is the new name of npmzip which will allow you to install offline npm packages by one file
You can install stuff from a tarball file, check out the npm documentation. You can find the URL of the forever tarball with npm view forever dist.tarball and download that. Try something like this:
curl -so forever.tar.gz `npm view forever dist.tarball 2> /dev/null`
npm install ./forever.tar.gz -g
But you might have to do this for all of the dependencies as well. There might be a better way but this is what I've found in my search.
Well.... after a day trying to make it work with above references (npmbox or offline-npm) came up with something way much simpler. Thanks to npmbox I have to say.
The idea is the keep the cache from the instance that has online access and then use it in the one offline.
In machine with internet:
1 - clear npm cache: npm cache clear
2 - install package, lets say its x.y.z: npm install -g **package.x.y.z**
3 - copy cache in to a folder... let's call it whatever (I assume npm cache is in root folder, not absolutely sure about that):
cp -R /.npm/* **/cache-whatever-folder**
In machine with no internet:
4 - take this cache-whatever-folder to the instance with no internet and after that, clean cache and install with it (I won't indicate how to copy the folder :)
npm cache clear
npm install --global --cache **/cache-whatever-folder** --optional --cache-min 99999999999 --shrinkwrap false **package.x.y.z**
Done
INSTALL PM2 OFFLINE:-
Tested on Node-v6.10.3 and Npm-3.10.10 on RHEL-7
Go to machine with internet connection:-
#npm install -g npmbox
#npmbox npmbox
#scp npmbox.npmbox root#offline-server-ip:.
Go to machine without internet connection :-
#ssh root#offline-server-ip
#tar --no-same-owner --no-same-permissions -xvzf npmbox.npmbox
#npm install --global --cache ./.npmbox.cache --optional --cache-min 99999999999 --shrinkwrap false npmbox
Go to machine with internet connection:-
#npm install pm2 -g
#npmbox pm2
#scp pm2.npmbox root#offline-server-ip:.
Go to machine without internet connection :-
#npmunbox pm2.npmbox --global
#pm2 ls
I created offline-npm for getting all the dependencies installed in a clean way. For modules without the use of node-gyp everything should work as described.
If you require node-gyp (which is usually installed online) consider copying ~/.node-gyp to that offline machine.
Try npmzip
npm install -g npmzip
npmzip <package>
You will get the tarball in the current directory
This may be moved to the target machine and :
npmunzip <tarball>
Using Yarn:
On the internet machine (configure local cache location):
yarn config set yarn-offline-mirror ~/yarn-offline-mirror/
On the offline machine (configure local cache location):
yarn config set yarn-offline-mirror ~/yarn-offline-mirror/
On the offline machine, Find out where is the global installation location:
yarn global bin
(Or set it with yarn config set prefix <file_path>)
On the offline machine, add it to your path. E.g.:
echo 'export PATH=$PATH:'"$(yarn global bin)" >> ~/.bashrc
source ~/.bashrc # reload
On the internet machine, download forever's dependencies:
mkdir new-cli-forever/
cd new-cli-forever/
yarn add forever
Then copy new-cli-forever/yarn.lock and ~/yarn-offline-mirror/ to the offline machine. (rm -rf new-cli-forever/ is ok now.)
On the offline machine, install forever from local cache:
cp /path/to/imported/yarn.lock .
cp -n /path/to/imported/yarn-offline-mirror/* ~/yarn-offline-mirror/
yarn global add --offline forever
rm -f ./yarn.lock
For more info, see my post here: https://assafmo.github.io/2018/04/11/yarn-offline.html
List the dependencies in bundledDependencies in your package.json, and then run npm pack to create a tarball. Get that over to the other machine, and either npm install <tarball>, or just crack it open manually.
https://github.com/npm/npm/issues/1349
npmbox is outdated
Use npm pack command (npm docs), no need to install anything.
Single package
If you want only one package (for example, forever), you can run:
npm pack forever
this command will fetch it to the cache, and then copy the tarball to the current working directory as -.tgz
Then, from the folder you created the package, you install it with:
npm install -g ./forever-x.y.z.tgz
Whole project
If you want a whole project to be installed offline, include a poperty in your package.json named bundleDependencies and list all dependecies you need in this field.
// package.json
"dependencies": {
"archiver": "^2.1.1",
"axios": "^0.16.2",
"body-parser": "^1.18.3"
},
"bundleDependencies": {
"archiver": "^2.1.1",
"axios": "^0.16.2",
"body-parser": "^1.18.3"
}
Then run npm pack.
It will create a .tgz file of your whole project and dependencias.
You just have to copy it to the offline server and untar.
On your local machine or any machine that has internet connection, do
npm install npm-bundle -g
npm install forever -g
Now, go to cd /usr/local/lib/node_modules/forever and do
npm-bundle
It will create a .tgz file. Now scp/ftp that .tgz file to the offline server and do
npm install forever -g
Reference: This blog
On an online machine do:
# change to desired packages
packages="pm2 yarn"
for pkg in $packages; do
mkdir "$pkg"
curl "$(npm view "$pkg" dist.tarball)" |
tar -xzC "$pkg" --strip-components 1
(cd "$pkg" && npm install)
done
tar -czf packages.tar.gz $packages
On the offline server do:
npm config set offline
tar -xzf packages.tar.gz
npm install -g pm2 yarn