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
  • 69,223
  • 56
  • 216
  • 327
  • What does the command "whereis sudo" gives? – Noosrep Nov 05 '18 at 14:55
  • whereis is also not found... same message – LogicOnAbstractions Nov 05 '18 at 14:56
  • Please update your question with the content of `~/.profile`, especially the lines containing PATH. – Soren A Nov 05 '18 at 14:56
  • 2
    Possible duplicate of [The command could not be located because '/usr/bin' is not included in the PATH environment variable](https://askubuntu.com/questions/452488/the-command-could-not-be-located-because-usr-bin-is-not-included-in-the-path) – karel Nov 05 '18 at 15:29
  • Not really - the answer to that question isn't appropriate here, without significant adaptation. If people make mistakes like this, why do we assume they have enough knowledge to be able to follow instructions that don't actually match their situation? – Zanna Nov 05 '18 at 15:45
  • I'd agree with Zanna here. I mean I've looked for $PATH/.profile/.bashrc before coming here but I realized I just lacked background knowledge to be able to first identify what happened (Zanna is right, I reproduced the error by ommitting $PATH). Then I lacked the knowledge to see how .profile/PATH/bashrc may or not be relevent in how to fix this. – LogicOnAbstractions Nov 05 '18 at 15:49

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
  • 69,223
  • 56
  • 216
  • 327