3

Every time I close my terminal and reopen it, simples command(e.g. ls) doesn't work. It shows the following error,

irfan@irfan-Y500-Elementery:~$ ls
Command 'ls' is available in '/bin/ls'
The command could not be located because '/bin' is not included in the PATH environment variable.
ls: command not found

I have to execute the following command export PATH=/usr/bin:/bin every time to correct this error,

irfan@irfan-Y500-Elementery:~$ export PATH=/usr/bin:/bin
irfan@irfan-Y500-Elementery:~$ ls
Assets   Documents        Example.java     Music       Public     Videos
Blender  Downloads        export           output.pdf  sudo
Desktop  Elementary Luna  jmonkeyplatform  Pictures    Templates

My questions is, why I have to do it every time? and what do I have to do to solve the repetition.

My /etc/environment files contains the following,

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
CLUTTER_PAINT=disable-clipped-redraws:disable-culling

Note : I am using ElementaryOS(based on Ubuntu 12.04)

Edit 1:

echo $PATH returns /usr/local/jre1.7.0_51/bin:

I followed this answer to set java path.

I added

PATH=/usr/local/jre1.7.0_51/bin:
export PATH 

to my /home/irfan/.bashrc file. I guess this caused the problem

  • 2
    If you don't run export PATH..., what is the result when you run echo $PATH? Also, try running echo 'PATH DEFAULT=${PATH}:/usr/bin' >> .pam_environment and rebooting. – Wilf Mar 02 '14 at 20:37
  • @Wilf I tried running echo 'PA.. and rebooting. But, echo $PATH shows only jdk on my path. – Quazi Irfan Mar 02 '14 at 21:14
  • 1
    Close-voters: This question says it's about ElementaryOS rather than Ubuntu so ordinarily it would be closed. But it already has a good answer that doesn't appear Elementary-specific at all and would help Ubuntu users too. In effect I think this question turned out, by the skin of its teeth, to be effectively on topic, and we shouldn't close it. As an separate reason, especially considering the current emphasis on deleting closed questions, this question will likely be deleted if it's closed, which would harm Ubuntu users who'd benefit from the answer. I recommend against closing this. – Eliah Kagan Mar 03 '14 at 02:04

1 Answers1

3

With your problem with the .bashrc file, your method of specifying this only:

PATH=/usr/local/jre1.7.0_51/bin:
export PATH 

likely overwrote the original $PATH - including those already specified. so, to add /usr/local/jre1.7.0_51/bin as a path, in a similar manner to my suggestion above:

echo 'PATH DEFAULT=${PATH}:/usr/local/jre1.7.0_51/bin' >> ~/.pam_environment

This should add it as a path without overwriting the others in $PATH. It should work if you reboot/logout & login/something like that - you will see it in echo $PATH if it works.

Wilf
  • 30,194
  • 17
  • 108
  • 164
  • I removed my jdk edit on PATH variable, and tried your command. But it shows me the following errtor, bash: .pam_environment: Permission denied. – Quazi Irfan Mar 02 '14 at 21:35
  • With the original command, you had to make sure the terminal wass in the home directory. see edit. – Wilf Mar 02 '14 at 21:36
  • It worked thanks. Don't know why, the system needed a reboot. echo $PATH shows /usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/jre1.7.0_51/bin::/usr/local/jre1.7.0_51/bin:/usr/local/jre1.7.0_51/bin – Quazi Irfan Mar 02 '14 at 21:51
  • One more question, what command should I used to append something to my PATH variable? – Quazi Irfan Mar 02 '14 at 22:07
  • In .bashrc or .profile, it is as simple as PATH="$PATH:/my/new/dir" (no spaces around the =!) – Rmano Mar 02 '14 at 22:29
  • 1
    Dunno why you need a reboot/whatever, just it does not always pick up the changes. To add something to $PATH, add it to .pam_environment similar to the method described above, or use @Rmano's method. – Wilf Mar 02 '14 at 22:32
  • 1
    See also https://help.ubuntu.com/community/EnvironmentVariables – Rmano Mar 02 '14 at 22:36
  • @Wilf If I use the command again, it replaces everything on pam_environment file. – Quazi Irfan Mar 04 '14 at 00:47
  • 2
    The best place to put environment variables is (at least on ubuntu) on .profile, because the file is sourced by lightdm before starting your session (other distros may differ). You need a login/logout before seeing the changes, a reboot is overkill. .pam_environment may be ok, but is overwritten if you change language configuration/support. And @iamcreasy, if you want to add something to a file, use >> instead of > in the redirection. – Rmano Mar 04 '14 at 04:17
  • 1
    @iancreasy - sorry - one > overwrites, two >> adds to it - added edit. – Wilf Mar 04 '14 at 13:50