My teacher wants to be able to compile our programs without having to type ./.

For example we would write:

g++ some_program.cpp -o some_program

He says to type:

  1. cp .bash_profile .bash_profile.ORIG
  2. Then load .bash_profile into text editor
  3. Then go to the end of the file PATH=$Path: and add a period
  4. export
  5. restart

My questions are:

  1. Do I just type cp .bash_profile .bash_profile.ORIG into the terminal right after I open it?
  2. How do I load it into my text editor?
  3. And how do I export it?
  • 4
    Adding the current directory symbol '.' to your PATH is generally viewed as a security risk, (or at least an endlessly revisited discussion point). (and your questions suggest that your teacher hasn't done wonders with other basic instructions) Here is a closely similar discussion: askubuntu.com/questions/320632/… – Theophrastus Jun 25 '15 at 23:42
  • 2
    I would seriously recommend finding a better teacher given that he did not know how to source a file in the shell, thought adding the current directory to the path was a good idea, and has not taught you how to open an editor. Three strikes. Feel free to let him know I said this. If you had a competent teacher you would not be asking these questions. I am not saying they are bad questions for a beginner, but your teacher should have already answered them. – hildred Jun 26 '15 at 1:32

1) Do I just type cp .bash_profile .bash_profile.ORIG into the terminal right after I open it?

Yes. You are essentially making a backup copy of your current ~/.bash_profile (assuming there is one).

2) How do I load it into my text editor?

It depends on what text editor you intend to use. I do this:

$ emacs ~/.bash_profile

but you could also do:

$ gedit ~/.bash_profile

There are heaps of text editors, of course, including nano or pico for in-terminal editing. So really just take your pick. If you don't have a favourite editor, nano is a good starter.


The line should not be PATH=$Path: It should be:


As Theophrastus says in the comment, this is a horrible security practise and generally should not be done. I think it's better practise to designate a directory where you code, and a directory where executables get stashed for testing and that is in $PATH. But if this is a school assignment, I guess you should do as your teacher says.

3) And how do I export it?

Add this line after the $PATH line:

export PATH

Note: your teacher is wrong. You do not need to restart. How would that be possible if you were maintaining a server? you'd kick everyone off and your users would be furious! All you need to do to load in new settings is:

$ source ~/.bash_profile

Good luck!

  • @ZachStow if his answer works for you, you should accept it so people like me don't come to answer it again. – Centimane Jun 27 '15 at 1:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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