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.
Related
I am new to Golang, I am following this tutorial https://golang.org/doc/tutorial/getting-started but for some reason I keep getting this message every time I try to run the code:
$GOPATH/go.mod exists but should not
I have tried to look at answers like this one: https://stackoverflow.com/a/62062562/9785222 but I dont understand what is GOPATH and where is it.
I am using Vi as an editor on Linux Fedora
GOPATH defaults to $HOME/go on Unix.
Remove the file $HOME/go/go.mod or explicitly set $GOPATH to a different directory.
$GOPATH should point out to the src directory, in my case in Debian, I set $GOPATH to /usr/local/go/src and the problem was solved.
export $GOPATH=/usr/local/go/src
What is GOPATH ?
GOPATH is a variable that defines a folder, under which GO expects our code to reside . For more details, you can check this link
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 am following instructions from here:
https://www.datacamp.com/community/tutorials/apache-spark-python#gs.WEktovg
I downloaded and prebuilt version of Spark , untarred it and mv it to /usr/local/spark.
According to this, this is all I should have to do.
Unfortunately, I can run the interactive shell as it cant find the file.
When i run :
./bin/pyspark
I get
-bash: ./bin/pyspark: No such file or directory.
I also notice that installing it this way does not add it to the bin directory.
Is this tutorial wrong or am I missing a trick?
You need to change your working directory to /usr/local/spark. Then this command will work.
And also, when you untar it, it usually will not add it to bin folder. You need to add it manually by adding the path to environment variables.
Update your working Directory to /usr/local/spark and execute the command. Hopefully this will fix the issue.
I am quite new to Linux so I'm sorry for my newbie question,
but for about and hour now I'm trying to add Node.js to $PATH with no luck :(
I've used the following line to add Node
PATH=$PATH:node-v0.10.24-linux-arm-armv6j-vfp-hard/bin
it worked, but when I logged off the terminal and logged in again, the path disappeared.
Later I tried adding the same line to .profile , .logins.defs and .bashrc.
All didn't work so I removed the line.
Please help me with this!
P.S , when I added the line to .profile I was able to call Node, but when I changed my directory in order to navigate to a Node project directory, I received the following error:
-bash: node-v0.10.24-linux-arm-armv6j-vfp-hard/bin/node: No such file or directory
You should add an absolute path, not a relative one. You added this to your path: node-v0.10.24-linux-arm-armv6j-vfp-hard/bin. That's a relative path, not an absolute one (absolute paths start with a /). You can change your line to:
PATH=$PATH:DIR/node-v0.10.24-linux-arm-armv6j-vfp-hard/bin
where DIR is the full path of the directory containing node-v0.10.24-linux-arm-armv6j-vfp-hard.
It's probably a good idea for you to read a bit on how this all works - it's not that complicated once you see it explained. See https://superuser.com/questions/238987/how-does-unix-search-for-executable-files for an example.
You have $HOME already set to your home directory.
So you can use this in your .profile:
PATH="$PATH:$HOME:$HOME/bin:$HOME/node-v0.10.24-linux-arm-armv6j-vfp-hard/bin"
If you set it as an absolute path you will not be able to copy that .profile to another user who is set up similarly.
I see there is another question that deals with installing node.js on Debian - and must admit I am surprised it is installed per-user. So if you do the install for another login you might want to copy your .profile to the new login to solve this same issue. There would be no per-user editing required if you use the $HOME variable like this. Just a simple copy or cut and paste.
For reference, here is that other question/answer: install node.js on debian
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