I'm on a unix box where I don't have root access.
I changed my .npmrc file (in my user's root directory) to:
prefix=~/global_npm
Now when I do "npm install -g packagename" it installs inside my global_npm directory. Which is good.
And then I gave myself path access to it by updating my .bashrc file with:
export PATH=$PATH:~/global_npm/bin
Do I need to do anything else? I think I need to set NODE_PATH but I'm not sure?
Many setups already expect binaries to be found in ~/.local/bin/. So this answer follows that convention. Other files will get installed to ~/.local/lib/node_modules/.
1. Configure npm
Run:
npm config set prefix '~/.local/'
This modifies ~/.npmrc to include this line:
prefix=~/.local/
2. Make sure ~/.local/bin exists and is in your PATH
Run echo "$PATH" to have a look at your path. If it does not include ~/.local/bin/ already, you will need to configure your system to include it.
mkdir -p ~/.local/bin
echo 'export PATH=~/.local/bin/:$PATH' >> ~/.bashrc
Replace .bashrc with the configuration file of the shell that you are using.
3. Install packages globally
npm install -g packagename
Sindre Sorhus has a great guide at github.com/sindresorhus/guides which I've reposted here.
Install npm packages globally without sudo on OS X and Linux
npm installs packages locally within your projects by default. You can also install packages globally (e.g. npm install -g <package>) (useful for command-line apps). However the downside of this is that you need to be root (or use sudo) to be able to install globally.
Here is a way to install packages globally for a given user.
1. Create a directory for your global packages
mkdir "${HOME}/.npm-packages"
2. Reference this directory for future usage in your .bashrc/.zshrc:
NPM_PACKAGES="${HOME}/.npm-packages"
3. Indicate to npm where to store your globally installed package. In your $HOME/.npmrc file add:
prefix=${HOME}/.npm-packages
4. Ensure node will find them. Add the following to your .bashrc/.zshrc:
NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
5. Ensure you'll find installed binaries and man pages. Add the following to your .bashrc/.zshrc:
PATH="$NPM_PACKAGES/bin:$PATH"
# Unset manpath so we can inherit from /etc/manpath via the `manpath`
# command
unset MANPATH # delete if you already modified MANPATH elsewhere in your config
MANPATH="$NPM_PACKAGES/share/man:$(manpath)"
Check out npm-g_nosudo for doing the above steps automagically
NOTE: If you are running OS X, the .bashrc file may not yet exist, and the terminal will be obtaining its environment parameters from another file, such as .profile or .bash_profile. These files also reside in the user's home folder. In this case, simply adding the following line to them will instruct Terminal to also load the .bashrc file:
source ~/.bashrc
Unless you require a package installation due to dependencies, which are rare, I would recommend you use NVM (https://github.com/creationix/nvm) to install Node.
If you do this without sudo, you will also not need to use sudo when globally installing modules.
My edit to Rowno's answer has been rejected and I can't make a comment yet so I'll just post my version of the lines added in .bashrc here.
The edit I made in it was adding export to the assignments of NODE_PATH and MAN_PATH, and then simplifying the MANPATH assignment. I also made : optional for NODE_PATH just in case it doesn't have a prior value. The other modifications here are just personal preference but I haven't included them in the original edit.
npm_global=~/.npm-global
export NODE_PATH="$npm_global/lib/node_modules${NODE_PATH:+:}$NODE_PATH"
PATH="$npm_global/bin:$PATH"
export MANPATH="$npm_global/share/man:$(unset MANPATH; manpath)"
Having export makes sure variables are shared across child processes that may need them (e.g. node and man), just in case they haven't been declared yet, or assigned with export attribute previously. Specifying export to PATH OTOH is very much optional.
I actually find it unusual to reset MANPATH before prepending a value to it because some scripts may also add custom values to it earlier. I recommend that the user makes sure .bashrc or any other user-based initialization scripts doesn't add other lines like this at least. For global configurations, I think the path should be added formally through /etc/manpath.config, or something similar, so it's a different worry most likely.
Either start a new terminal session or just type "source ~/.bashrc"
Now you can run any executables like grunt/bower/yo/whatever (depending on what npm packages you have installed globally).
P.S. BTW changing the global npm directory can be done with a command: npm config set prefix ~/global_npm
That's pretty much all you need to do if you are installing binary utilities (which I gather you are as you updated your PATH).
NODE_PATH will only need to be set you have installed a module that you want to require() from unrelated node scripts, but you shouldn't really do this anyway. Modules that are required as dependencies for other modules/scripts should be installed locally (i.e. specified in a package.json) as that way you keep strict control over versions.
Edit:
The accepted answer here explains it much better than I was able to:
How do I install a module globally using npm?
The answer by Rowno works for me, but only after making a slight edit to step 4:
NODE_PATH="$NPM_PACKAGES/lib/node_modules:$NODE_PATH"
and changed it to:
NODE_PATH="$NPM_PACKAGES/node_modules:$NODE_PATH"
Try to switch user:
su - username
If you don't have another user try:
useradd username
Then,
su - username
Related
I've spent several hours trying solutions, but realized I didn't fully understand the problem. Now that I think I understand the problem, I can't find a proper solution. It is possible I'm simply misunderstanding solutions I've found, so if this is a repetitive post I apologize.
My issue is my Node global install. I ran node config ls -l and saw something perplexing.
My user-agent prefix is /Users/me/.npm and my builtin prefix is /usr/local, but has been overridden (as expected).
All of my previous global installs are under /usr/local, also as expected. My new global installs are going under /Users/me/.npm/lib/node_modules, which I also expected since I set a prefix manually from another solution.
My global config is /Users/me/.npm/etc, which DOES NOT EXIST. The etc directory doesn't exist and the global config doesn't seem to exist. There is not a global config under /usr/local/etc, but /usr/local/etc does exist.
I have tried changing PATH under .bashrc and .bash_profile. When I check my files, I no longer even have a PATH=$PATH:directory in .bash_profile, and .bashrc is completely empty.
My global packages which are being executed are the ones installed under usr/local/lib/node_modules. The ones being installed are now going to /Users/me/.npm/lib/node_modules.
I want to set all of my globals back to /usr/local, so my packages install and execute from /usr/local/lib/node_modules.
It was a misunderstanding on my part, and the answer posted here resolved my issue.
( https://stackoverflow.com/a/14840304/11046625 )
I just installed racer using cargo. After installing it say this:
Installing /home/karthik/.cargo/bin/racer
warning: be sure to add `/home/karthik/.cargo/bin` to your PATH to be able to run the installed binaries
How do I do this? Googling didn't help. Also, Should I be setting a PATH variable for cargo bin as well?
Edit: OS is Ubuntu 14.04 and I have super user access
You have to add the cargo bin path to your PATH variable and set the RUST_SRC_PATH in .profile or .bash_profile.
Related unix.stackechange question
There are two steps:
(1) Add the Cargo bin to your PATH variable. You can run $ whereis cargo to find the bin path, and then do $ sudo -H gedit /etc/environment where you can add that new path section to your current PATH variable. You will need to save and close the file (and you can ignore the error message in the terminal during the saving portion) in order for it to take effect.
(2) Run $ rustup component add rust-src to download the necessary Rust source files for you.
At this point Racer should work properly.
This is based on the answer here.
I often have this issue when configuring a software on linux. When I install some library (for instance libsodium) by cloning the repository then doing the usual
./autoconf.sh
./configure
make
make install
I get everything install in /usr/local/ which is absolutely good for me.
Unfortunately, when I try to install something that depends on this library (for example libzmq, I get the issue
configure: error: Package requirements (libsodium) were not met:
No package 'libsodium' found
Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.
Alternatively, you may set the environment variables sodium_CFLAGS
and sodium_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.
I guess the problem is because configure is looking on usr/ and not /usr/local. The ugly workaround is to install everything in usr/ instead of /usr/local. A more brutal approach would be to copy all what is installed in /usr/local into /usr/.
What is the correct solution when facing this kind of issues?
How should I adjust the PKG_CONFIG_PATH or the sodium_LIBS?
Set the PKG_CONFIG_PATH to /usr/local by means of your shell.
Some work with export, some with other means.
E. G.
export PKG_CONFIG_PATH=/usr/locall
run:
$ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/
prior to ./autogen.sh && ./configure.
When I run
npm ls -g
I get back
-> /usr/local/lib64/usr/local/bin
(empty)
Which is obviously incorrect. Using locate I can see my global modules are installed at /usr/lib64/node_modules. How do I go about correcting this issue? (I'm running gentoo amd64.)
npm uses a .npmrc file which should be in your home directory. (ie ~/.npmrc) In this file you should see a key value pair with the key being "prefix". Try setting the value to something like "/usr/lib64". So your .npmrc file would have the following in addition to whatever else you put in it:
prefix = /usr/lib64
For those on Windows the npmrc file can be found in C:\path\to\nodejs\node_modules\npm\npmrc. You can change the prefix as mentioned in the answer by cmaxo. By default it's usually something like ${APPDATA}\npm.
I want to run 'make install' so I have everything I need, but I'd like it to install the things in their own folder as opposed to the system's /usr/bin etc. is that possible? even if it references tools in the /usr/bin etc.?
It depends on the package. If the Makefile is generated by GNU autotools (./configure) you can usually set the target location like so:
./configure --prefix=/somewhere/else/than/usr/local
If the Makefile is not generated by autotools, but distributed along with the software, simply open it up in an editor and change it. The install target directory is probably defined in a variable somewhere.
Since don't know which version of automake you can use DESTDIR environment variable.
See Makefile to be sure.
For example:
export DESTDIR="$HOME/Software/LocalInstall" && make -j4 install
make DESTDIR=./new/customized/path install
This quick command worked for me for opencv release 3.2.0 installation on Ubuntu 16. DESTDIR path can be relative as well as absolute.
Such redirection can also be useful in case user does not have admin privileges as long as DESTDIR location has right access for the user. e.g /home//
It could be dependent upon what is supported by the module you are trying to compile. If your makefile is generated by using autotools, use:
--prefix=<myinstalldir>
when running the ./configure
some packages allow you to also override when running:
make prefix=<myinstalldir>
however, if your not using ./configure, only way to know for sure is to open up the makefile and check. It should be one of the first few variables at the top.
If the package provides a Makefile.PL - one can use:
perl Makefile.PL PREFIX=/home/my/local/lib LIB=/home/my/local/lib
make
make test
make install
* further explanation: https://www.perlmonks.org/?node_id=564720
I tried the above solutions. None worked.
In the end I opened Makefile file and manually changed prefix path to desired installation path like below.
PREFIX ?= "installation path"
When I tried --prefix, "make" complained that there is not such command input. However, perhaps some packages accepts --prefix which is of course a cleaner solution.
try using INSTALL_ROOT.
make install INSTALL_ROOT=$INSTALL_DIRECTORY