setting path no profile files or local paths

Asked by john payton

As a beginner have just set up UBUNTU and loaded emc2 and ngcgui.
I have a directory emc and a sub directory ngcgui. I want to add them to the PATH but don't seem to have a file bash_profile or etc/profile on my system.
Can someone give me a safe way to set this path as I am loave to experiment and lose what i have already achieved
John

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu bash Edit question
Assignee:
No assignee Edit question
Solved by:
Eliah Kagan
Solved:
Last query:
Last reply:
Revision history for this message
marcobra (Marco Braida) (marcobra) said :
#1

New to Ubuntu:
- read the Ubuntu Manual, it's very informative: http://ubuntu-manual.org/
Click on the "download Button" to download the latest PDF version.

http://ubuntuguide.org/wiki/Ubuntu:Natty
- Nascondi testo citato -

The Ubuntu 11.04 Unity interface
http://theravingrick.blogspot.com/2011/04/my-effort-at-writing-help-for-unity.html
The Unity interface: http://www.omgubuntu.co.uk/natty/#what

- https://help.ubuntu.com/community/SwitchingToUbuntu/FromWindows
- The Ubuntu pocket guide: http://www.ubuntupocketguide.com/
- The online help https://help.ubuntu.com/10.10/index.html

Revision history for this message
Best Eliah Kagan (degeneracypressure) said :
#2

If you want to set it for a single user, the file you'd want to use is called .bash_profile (it starts with a dot), and it's located in your home directory.

So if your username is john, the file is located at /home/john/.bash_profile.

That file might not exist. If it doesn't, then use .bash_login if that exists, and otherwise use .profile. (These files would be in the same location.)

Files that start with a . (dot) are, by default, hidden in Nautilus (the file browser). To show them, go to Edit > Preferences in a Nautilus window, and in the Views tab, check the box labeled "Show hidden and backup files."

Most likely, you don't have .bash_profile or .bash_login, but you do have .profile, and it includes something like:

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

That checks to see if a bin subdirectory of your home directory exists, and if it does, it adds it to the beginning of your path. You can do the same sort of the thing for the directories you've just created. (Or, if you like, you can just include them in your path without an existence check, by leaving out the if and fi lines--if you do that, it's good form *not* to indent the PATH=... line.)

The key point here is that you want to keep whatever is *already* in the PATH, so you want to assign a string to PATH that is $PATH (the PATH environment variable, expanded, i.e., the text contained by that variable), concatenated with whatever you're adding to it.

You'll have to log out and back in to get the new PATH, after modifying it using the above method.

Revision history for this message
Eliah Kagan (degeneracypressure) said :
#3

(To clarify, .bash_profile, .bash_login, and .profile are all for a single user, whereas /etc/profile -- it starts with a / -- is systemwide. See http://manpages.ubuntu.com/manpages/natty/en/man1/bash.1.html for details, and note that ~ expands to your home directory -- e.g., /home/john -- in essentially the same way that $PATH expands to the text of your executable search path.)

Revision history for this message
john payton (johnpayton759) said :
#4

Thanks Eliah Kagan, that solved my question.

Revision history for this message
john payton (johnpayton759) said :
#5

Many thanks for your help, just one question I can't seem to find in the
manual.

If I have a structure home/emc/gui
and I want to add to the PATH both emc and gui can I just add emc/gui or
do I have to add both emc and emc/gui

Many thanks John

Revision history for this message
Eliah Kagan (degeneracypressure) said :
#6

First of all, I highly recommend you get in the habit of including the leading slash when a path is absolute. For example is, I might talk about the directory called gui, inside /home/emc. I didn't put a slash in front of gui, because that's a *relative* path--relative to /home/emc. Similarly, I might talk about the directory emc/gui, inside /home. But /home/emc (and in the second example, /home) does have a leading slash, because that is an absolute path. Correctly including (or correctly not including) the leading slash is important for making your communication with others clear; it is essential if you want the configuration files and scripts you write, and the commands you run, to work.

Assuming you're referring to /home/emc/gui, and the executables that you want to be found in the path are located in that directory and not in /home/emc (which seems likely, as it is unusual for a user's home directory to directly contain executables), you can just include /home/emc/gui in the path. You do not want to include emc/gui in the path, because that would make it so that, whatever directory someone is in, the gui subdirectory of the emc subdirectory of that directory would be searched when they tried to invoke a program. (For example, if someone were in a directory called /home/john, then the directory /home/john/emc/gui would be searched, or if that directory didn't exist then nothing would be searched for the emc/gui path element; the correct directory, /home/emc/gui, would not be searched, unless you happened to be in the /home directory, which one is rarely in.)

Indeed, you should not include a directory in your path unless you have reason to do so. If /home/emc doesn't directly contain any of the programs you want found in your path, and they're all in /home/emc/gui, then you can just include /home/emc/gui in your PATH.

Revision history for this message
Eliah Kagan (degeneracypressure) said :
#7

Correction: "For example is, I might" --> "For example, I might"

Revision history for this message
john payton (johnpayton759) said :
#8

Many thanks for taking time to reply

John