

Source the ~/.profile or ~/.bash_profile and you should be able to install and use npm packages globally with your user even without root access. Marcs-MBP-3:masterclass Marc npm install npm WARN deprecated gulp-uglifyjs0.6.2: Since gulp-sourcemaps now works, use gulp-uglify instead npm WARN deprecated babel-preset-es20156.24.1: Thanks for using Babel: we recommend using babel-preset-env now: please read babeljs.

#SUDO NPM INSTALL UPDATE#
Optionally update the $MANPATH variable for npm packages which ship man pages.Īdd the following line to your ~/.profile or ~/.bash_profile file. 16 for some packages I have to run sudo npm install -g while for others npm install will suffice. NODE_PATH="$HOME/.node/lib/node_modules:$NODE_PATH" Running sudo npm install (without -g) will create a local directory that can only be altered by the root user. Note: This may be your ~/.bash_profile if you're in Ubuntu. Note: If the file doesn't exist, it did not for me, just create it and save those contents inside.Īdd the new bin and node_modules folders to your $PATH and $NODE_PATH variables by adding the following lines to your ~/.profile file. Start using sudo-prompt in your project by running npm i sudo-prompt. The only way I can get no errors is to run sudo npm install but I read this is not a good idea. Latest version: 9.2.1, last published: 3 years ago. Tell npm where to store the globally installed packages by adding the following line to your ~/.npmrc file. Run a command using sudo, prompting the user with an OS dialog if necessary. If you still can't run nodemon, you can try typing npx nodemon index.js. So your command to install nodemon should look like this sudo npm install nodemon -g. See willvincents response below to configure npm. When installing npm package globally on macOS and Linux you need to use sudo. With the next steps, we're going to use your home directory for those files.įirst we create a directory in your home directory where all the npm packages will be installed. The npm install part is the same regardless, the sudo just gives it the permissions (privileges) it needs. Today we're going to setup our npm installation to be used without root or sudo rights.īy default, if you install packages globally with npm, npm tries to install them into a system directory (i.e.
#SUDO NPM INSTALL HOW TO#
The next section will show how to use an alternate repository to install different versions of Node.js. At this point you have successfully installed Node.js and npm using apt and the default Ubuntu software repositories. I'm saving this as a gist and modifying it to ensure that if the original blog post disappears it lives on somewhere.Īdded some notes for Ubuntu 18.04 and similar. sudo apt install npm This will allow you to install modules and packages to use with Node.js.
