LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Changing the environment variable permanently in Ubuntu 10.10 (https://www.linuxquestions.org/questions/linux-newbie-8/changing-the-environment-variable-permanently-in-ubuntu-10-10-a-877967/)

anis_huq 04-30-2011 02:45 AM

Changing the environment variable permanently in Ubuntu 10.10
 
Friends, I want to make change to environment PATH system wide. Because I have program called "md5". I want to execute it from anywhere (i.e any directory).

My md5 program is located at "/home/ahuq/MappingServer/md5_program". So what I did was to put: "export PATH=$PATH:/home/ahuq/MappingServer/md5_program" in the running SHELL. This only makes temporary changes and lets me run the "md5" program from anywhere temporarily. But I want to make this change permanent. So what I did was to put the "PATH=$PATH:/home/ahuq/MappingServer/md5_program" line into the "/etc/environment" file. This screwed everything up and then for a while I couldn't execute anything from SHELL. I knew the absolute path of "nano" editor and used it to modify the file (i.e. /etc/environment) back to its original condition. This fixed the problem and now I can run programs like "ls" from the SHELL.

But still I need a way to permanently add the path of "md5" to the environment. How can I do this in Ubuntu 10.10? Which file needs to edited?

Do I just logout or do I have to restart the system to make the changes active?

Bye.

Hevithan 04-30-2011 03:02 AM

Quote:

Originally Posted by anis_huq (Post 4341676)
So what I did was to put: "export PATH=$PATH:/home/ahuq/MappingServer/md5_program" in the running SHELL. This only makes temporary changes and lets me run the "md5" program from anywhere temporarily. But I want to make this change permanent.

I'm going out on a limb here ... In other words: I only understand vaguely what you mean.


What I get is that you want all users to be able to access this program, and all I can think of is: Have you done a $ chmodcommand? ch allows whoever you add to it, permission to access files for their own use or reading ... I don't know if that applies to you, But it sounds like it may.

From washington.edu:

To change the mode of a file, use the chmod command. The general form is

Code:

    chmod X@Y file1 file2
where: X is any combination of the letters `u' (for owner), `g' (for group), `o' (for others), `a' (for all; that is, for `u,g, and o'); @ is either `+' to add permissions, `-' to remove permissions, or `=' to assign permissions absolutely; and
Y is any combination of `r', `w', `x'. Following are some examples:
Code:


    chmod u=rx file        (Give the owner rx permissions, not w)
    chmod go-rwx file      (Deny rwx permission for group, others)
    chmod g+w file        (Give write permission to the group)
    chmod a+x file1 file2  (Give execute permission to everybody)
    chmod g+rx,o+x file    (OK to combine like this with a comma)

THIS is a link to their site.



Quote:

Do I just logout or do I have to restart the system to make the changes active?
With alot of changes you don't really have to. But when I make a change or install a new program, I generally do a restart for 2 reasons.

1) If it causes the system to malfunction or run undesirably, I know what the reason is.

2) From what I understand, Linux holds onto processes as long as it is using them, So I like to restart and have it be as fresh as possible before running new things, or working with changes I have made.


Hope this info is helpful, and if not ... Well I tried :p
Best of luck!

spankbot 04-30-2011 03:20 AM

You need to add that PATH statement to your .bashrc file (/home/ahuq/.bashrc).

Let me know if you need more help, and don't forget to click the little "yes" button if this helped you.

thund3rstruck 04-30-2011 04:56 PM

Quote:

Originally Posted by spankbot (Post 4341695)
You need to add that PATH statement to your .bashrc file (/home/ahuq/.bashrc).

You could always put the PATH assignment in ~/.profile since that's the last of the files read/used by bash (.bashrc will run every time a new shell is started; even after logging in).

anis_huq 04-30-2011 06:40 PM

@spankbot......... I put in the line "PATH=¤$PATH:/home/ahuq/MappingServer/md5_program" at the end of the "/home/ahuq/.bashrc" file. Then logged out of the SHELL and went in again. It did not work:
root@ahuq-kitchen:/home/ahuq# md5 -sanis
No command 'md5' found, did you mean:
Command 'cd5' from package 'cd5' (universe)
Command 'mdu' from package 'mtools' (main)
Command 'mdb' from package 'mono-debugger' (universe)
md5: command not found

But when I did "export PATH=$PATH:/home/ahuq/MappingServer/md5_program" on the SHELL, the program "md5" became available temporarily.

root@ahuq-kitchen:/home/ahuq# md5 -sanis
MD5 ("anis") = 38a1ffb5ccad9612d3d28d99488ca94b

@thund3rstruck.... the same thing happened when I put "PATH=$PATH:/home/ahuq/MappingServer/md5_program" at the end of the .profile file. I couldn't run "md5".

Maybe I am putting the PATH statement in the wrong place of the above mentioned files. There are a lot if-else-fi structures inside those two files. Do I need to put the PATH statement inside any of those structures?

thund3rstruck 04-30-2011 06:58 PM

Quote:

Originally Posted by anis_huq (Post 4342287)
@thund3rstruck.... the same thing happened when I put "PATH=$PATH:/home/ahuq/MappingServer/md5_program" at the end of the .profile file. I couldn't run "md5".

@Anis,

The "$PATH" variable defines the directories the shell should search to find executable files. For example see the ~/.bash_profile script below:

Code:

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs
PATH=$PATH:$HOME/bin:$HOME/Test
export PATH

I have placed a script called 'Resize Images.sh' into a folder $HOME/Test. By adding $HOME/Test to .bash_profile as demonstrated above I can open any terminal and type:

Code:

$ Re[tab]
And bash will find my script and I can run it. So change your line to:

Code:

PATH=$PATH:$HOME/MappingServer/md5_program
export PATH

FYI, I'm on a Fedora machine so if your Ubuntu doesn't have .bash_profile then look for .profile or of course you can use .bashrc as mentioned above


Regards,

spankbot 05-01-2011 02:13 AM

@anis. Sorry, I assumed you knew you needed to include the export command in your .bashrc or .bash_profile file. You can do it all in one step too...

export PATH=$PATH:/home/ahuq/...


All times are GMT -5. The time now is 04:09 AM.