I am using Ubuntu 16.04 LTS. I am really new to Linux.

I created a softwares directory within the Downloads dir for all the software and added it to my PATH. Then I was advised that it's better to create a bin directory in your home, instead of keeping directories such as Downloads in the PATH. So, I did it. Now, my problem, I have both the directories in the PATH and some of my tools are not running due to this reason.

I did try some of the suggestions given in the posts here but it didn't work for me and since I am new, I am bit scared to experiment that I'll mess up every thing.

My PATH

$ echo $PATH 
/home/gjjha/bin:/home/gjjha/bin:/home/gjjha/bin:/home/gjjha/Downloads/softwares/ncbi-blast-2.5.0+/bin:/home/gjjha/bin:/home/gjjha/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin://home/gjjha/Downloads/softwares/ncbi-blast-2.5.0+:/gjjha/Downloads/softwares/ncbi-blast-2.5.0+/bin:/home/gjjha/home/gjjha/Downloads/softwares/ncbi-blast-2.5.0+/bin:/gjjha/Downloads/softwares/ncbi-blast-2.5.0+/bin:/gjjha/Downloads/softwares/ncbi-blast-2.5.0+/bin:/gjjha/Downloads/softwares/ncbi-blast-2.5.0+/bin:/gjjha/Downloads/softwares/bowtie2-2.2.9/index:/home/gjjha/Downloads/softwares/tophat-2.1.1:/gjjha/Downloads/softwares/bowtie2-2.2.9/index:/home/gjjha/gjjha/Downloads/softwares/bowtie2-2.2.9/index:/home/gjjha/Downloads/softwares/tophat-2.1.1:/home/gjjha/bin:/home/gjjha/bin/blastdb:/home/gjjha/bin/blast+2.5:/home/gjjha/blast+2.5/bin:/home/gjjha/blast+2.5/bin:/home/gjjha/bin/ncbi-blast-2.5.0+/bin

I want to remove the softwares dir and duplicates and want to keep /home/gjjha/bin since all softwares are in bin dir now.

Commands I tried:

PATH=echo $PATH | sed -e 's/:\/home\/wrong\/dir\/$//'
PATH= echo $PATH | sed -e 's/:/home/gjjha/Downloads/softwares/ncbi-blast-2.5.0+/bin/$//'
PATH=${PATH/%:/home/wrong/dir//}
PATH=${PATH%:/home/gjjha/Downloads/softwares//}
PATH=${PATH%:/home/gjjha/Downloads/softwares/ncbi-blast-2.5.0+/bin/}

I checked (even after rebooting), the softwares dir is still there.

  • 1
    Where did you set your path? You must have edited some config file. – Zanna Mar 12 '17 at 11:29
  • 2
    Trying to edit variables on the fly with sed or parameter substitution is not the right way to approach this. Revert the changes you made then logout and login. – steeldriver Mar 12 '17 at 13:32
  • 1
    Please remove this crossposting. – Cyrus Mar 12 '17 at 16:22
  • @Zanna I have added the path using vim .bashrc every time. – Neels Mar 14 '17 at 9:54
  • well you need to remove whatever you added to your .bashrc to set the PATH. Then it will be overidden by /etc/environment when you log out and back in. Then you can put the path you want in .profile (more appropriate than .bashrc) – Zanna Mar 14 '17 at 9:58

On my vanilla install of 16.04, the PATH variable is set from .profile for login shells

First save your current PATH to a text file:

echo $PATH > currentpath.txt

I find it easiest to then open a new shell and do

sudo vi .profile

now edit or add the line to set the correct path

PATH="..."

with the path that you want inside the quotes.

The default path:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"

(And it works from left to right - if an executable with the same name exists in /usr/local/sbin and /usr/bin, the version in /usr/local/sbin will be called when you type the name)

Press esc and write and quit with

:wq

If you don't know vi you could use nano to edit the .profile file. Might be easier.

Restart.

I did this so that my local bin folder was in the path for executables. Dunno why it wasn't by default, but hey.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.