0

I am trying to solve “how to add path permanently” using ubuntu 14.04. If I had a program say samtools-1.2 that I wanted to add to path I think I would do:

export PATH=$PATH:home/cmccabe/Desktop/NGS/samtools-1.2 >> .bashrc

Then to verify:

cat ~/.bashrc
2

2 Answers 2

0

To accomplish this you will want to create a new file in /etc/profiles.d/ with which ever name you want but making sure it ends with .sh for example... samtools.sh then inside the file place the following:

#!/bin/sh
export PATH=$PATH:/home/cmccabe/Desktop/NGS/samtools-1.2

Afterwards you'll want to run source /etc/profile via command line.

Note: export PATH=$PATH:home/cmccabe/Desktop/NGS/samtools-1.2 is missing a slash after the : character.

0
0

Shorter answer.

So are you 100% sure you know what you are doing here even if the command works? Because to my eyes, adding a directory on the user’s Desktop permanently to the system PATH seems a bit off to me. Stuff like this should just be installed as a system-wide install using sudo make install after the source code is compiled.

That said, here is my breakdown on what you are attempting to do, why it’s not working, what can be done to remedy it and past that—like I just said—why this is not a great idea.

Longer answer.

First, this command won’t do anything:

export PATH=$PATH:home/cmccabe/Desktop/NGS/samtools-1.2 >> .bashrc

It mixes up a few concepts incorrectly.

  • First, if you start the command with export PATH= and all that will do is assign a new PATH value.
  • Next, the path you are adding is incorrect: home/cmccabe/Desktop/NGS/samtools-1.2. If anything it should be /home/cmccabe/Desktop/NGS/samtools-1.2; note the leading slash in front of that path.
  • Finally the >> .bashrc is somewhat correct but what happens before it is so incorrect it doesn’t matter. The >> tells Bash to append what preceded it to .bashrc. And since first command is export PATH=, that doesn’t output anything. So all that gets appended to .bashrc is an empty line. And the .bashrc should be your user’s home directory so be sure to prepend the ~/ to the name like this: ~/.bashrc.

The real command if this is what you wanted the command to be would be something like this; but please don’t run it:

echo export PATH=$PATH:/home/cmccabe/Desktop/NGS/samtools-1.2 >> ~/.bashrc

The key here is echo which would just print whatever follows it—without acting on it—into .bashrc. And then you would run source ~/.bashrc and if you run an echo $PATH it should be all set.

All that said, this doesn’t seem like a great idea.

This is your system so do with it as you wish. But looking at what samtools-1.2 is, that’s just source code for the program. If you compiled it then maybe that PATH setting of /home/cmccabe/Desktop/NGS/samtools-1.2 would make sense. But even then the best way to deal with binaries is to actually install them on the system via sudo make install which would place all related files in the correct places and then just install the samtools binary into /usr/local/bin which should already be a part of your PATH.

That said, if you simply did a basic compile of samtools-1.2 and wanted to test it out, then setting it to point to a directory on your user’s desktop makes sense. But past any of that, your question is about permanently adding a program to your path. And in that case I would never recommend you ever permanently add a directory on a user’s desktop to your PATH. The risk of losing something sitting on your desktop is just too great.

Not the answer you're looking for? Browse other questions tagged .