1

Okay. I don't just copy-paste commands from the net, and I didn't see how/why that one would mess things up, but here....

I wanted to configure webstorm for dev. So I followed these instructions:

$  mkdir ~/.npm-global # directory where npm will install packages
$  npm config set prefix '~/.npm-global' # configure npm
$  echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.profile #add directory to path
$  source ~/.profile # refresh path for current session

Now if I enter most commands, I get this:

anonymous@anonymous:/home$ sudo nano ~/.profile
Command 'sudo' is available in '/usr/bin/sudo'
The command could not be located because '/usr/bin' is not included in the PATH environment variable.
sudo: command not found

I don't see how/why this should break pretty much all my commands. Did he override whatever was in PATH, instead of appending? How do I fix this?

Yes it looks like he did, here's my echo $PATH:

anonymous@anonymous:/home$ echo $PATH
/home/anonymous/.npm-global

Content of ~/.profile:

# set PATH so it includes user's private bin directories
PATH="$HOME/bin:$HOME/.local/bin:$PATH"
export PATH=~/.npm-global
Zanna
  • 70,465

1 Answers1

1

The instructions told you to run this command:

echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.profile #add directory to path

It seems you actually ran:

echo 'export PATH=~/.npm-global' >> ~/.profile

The problem is that you missed :$PATH.

$PATH is expanded to its value, which, all being well, should be something like /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games. Notice that the directories in PATH are colon (:) separated. That's why the original command has PATH=/new/path:$PATH - this puts the new path at the start of the reconstructed PATH variable.

I recommend you quote PATH assignments. You don't need to export PATH, because it's already in the environment and will remain so.

Replace the last line of your ~/.profile with

PATH="$HOME/.npm-global/bin:$PATH"

and all should be well.

I added /bin because the executables are probably in there, as the instructions suggest, but if for some reason they are not, you can adjust as appropriate. Path lookup is not recursive: the actual directory where the executable you want Bash to find is must be given in PATH. I also put $PATH first, but you can put it at the end. If there are two commands in PATH directories with the same name, the one closest to the start of PATH will be run.

Note: if you need to use critical commands when your PATH is broken, you can use their full paths, i.e /usr/bin/sudo. But if you haven't edited /etc/environment (which in general you probably shouldn't!) you can run source /etc/environment to get a sane PATH.

Zanna
  • 70,465