LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-25-2007, 12:49 PM   #1
Ninju
LQ Newbie
 
Registered: Sep 2007
Posts: 15

Rep: Reputation: 0
Setting environmental variables


I'm sure this is a major noob question, but I'm not sure how to do it.

Basically, I'm having trouble installing RMagick, and the only solution I can find to the error I'm getting is to set an environmental variable. Now, the solution says to put this in one of my startup files:

export LD_LIBRARY_PATH=/usr/local/lib

Now, I run that in terminal and it doesn't make a noticeable difference (i.e. doesn't solve my problems). I've tried replacing lib with lib64, and I still get the error when trying to install RMagick, so I'm assuming this line needs to be put in a startup file as it says in the solution I read, or there is a special command in terminal I can run to set the variable. If I need to put it a startup file, err... which one? I don't want to break anything.

I'm running Fedora Core 5 (x86_64).
 
Old 09-25-2007, 01:46 PM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958
If you use that line as-is, you simply replace the previous entry with '/usr/local/lib'. IOW, that becomes the only path available to that shell. You need to enter the entire list of paths you want (and in the order you want them searched):

export LD_LIBRARY_PATH="/usr/local/lib:/usr/lib"

You can see what the current setting of an environment variable is with 'echo $VARIABLENAME', or see all of them at once with the 'env' command.

By "startup files", this usually means /etc/bashrc, which is the basic system config file for bash. You can also put it in ~/.bashrc if you only want the setting to affect a single user.

And you don't have to worry about breaking anything, usually. Using the above line in a shell only sets the variable for that session; it doesn't affect the rest of the system. And global settings can easily be fixed by simply reversing the setting. At the very worst, if you find you've broken some necessary program or something, you might have to boot into administrative mode or use a different shell, such as /bin/sh, to fix things.

Last edited by David the H.; 09-25-2007 at 01:51 PM.
 
Old 09-25-2007, 03:19 PM   #3
Ninju
LQ Newbie
 
Registered: Sep 2007
Posts: 15

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by David the H. View Post
If you use that line as-is, you simply replace the previous entry with '/usr/local/lib'. IOW, that becomes the only path available to that shell. You need to enter the entire list of paths you want (and in the order you want them searched):

export LD_LIBRARY_PATH="/usr/local/lib:/usr/lib"

You can see what the current setting of an environment variable is with 'echo $VARIABLENAME', or see all of them at once with the 'env' command.

By "startup files", this usually means /etc/bashrc, which is the basic system config file for bash. You can also put it in ~/.bashrc if you only want the setting to affect a single user.

And you don't have to worry about breaking anything, usually. Using the above line in a shell only sets the variable for that session; it doesn't affect the rest of the system. And global settings can easily be fixed by simply reversing the setting. At the very worst, if you find you've broken some necessary program or something, you might have to boot into administrative mode or use a different shell, such as /bin/sh, to fix things.
Thank you so much. I did a couple other things, but I'm pretty sure what you've told me here has been the reason it's worked. I really can't thank you enough.
 
Old 09-25-2007, 05:29 PM   #4
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 63
If you set the LD_LIBRARY_PATH in a user's ~/.bashrc, it is a good idea to add to the LD_LIBRARY_PATH, not replace it. i.e.
Code:
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib"
The reason applies also to MANPATH, PATH and other lists, and is as follows. The system-wide shell configuration files, /etc/profile and /etc/bash.bashrc are read before the user-specific ~/.bashrc. Thus if the system administrator adds something to the LD_LIBRARY_PATH, perhaps for some application you use, you do not want to over-write it.

e.g. The system administrator installs a crucial package in /opt/important, and needs /opt/important/lib in the LD_LIBRARY_PATH for that application to run. He modifies the /etc/profile, setting LD_LIBRARY_PATH with this command:
Code:
export LD_LIBRARY_PATH="/opt/important/lib"
When you log in, this is executed first, and then your ~/.bashrc is executed. If you do this:
Code:
export LD_LIBRARY_PATH="/usr/local/lib"
...you will replace the original path set in the /etc/profile and the crucial app will cease functioning. You could of course explicitly set both paths in your ~/.bashrc like this:
Code:
export LD_LIBRARY_PATH="/opt/impoprtant/lib:/usr/local/lib"
...but maybe the system administrator would like to change this in the future, and it would be a pain to have to update your own ~/.bashrc each time (s)he does this. Hence the suggestion at the top of this post.

This sort of thinking is not so important if you are the sole user of your machine, but it's a good habit to get into - one day you may have to work in a large multi-user environment, and you should know how not to annoy your system administrators!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Environmental Variables danglingpointer Slackware 13 01-06-2005 01:36 AM
environmental variables msound Programming 0 08-21-2004 08:06 PM
environmental variables? blackzone Linux - General 1 08-06-2004 04:44 AM
environmental variables mbhenry Linux - General 6 09-18-2003 12:41 PM
Setting environmental variables in mandrake inprogress Linux - Newbie 4 06-07-2003 09:03 AM


All times are GMT -5. The time now is 01:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration