Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

My variables are

LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib
ORACLE_HOME=/usr/lib/oracle/11.2/client64

How to save these variables permanently ?

share|improve this question
    
The other answers on this page are great. One small recommendation would be to add /usr/lib/oracle/11.2/client64/lib in a new file under the /etc/ld.so.conf.d/ path. Then you don't need to set LD_LIBRARY_PATH, see also here. –  Elliott Frisch Feb 28 at 18:19
add comment

2 Answers

up vote 7 down vote accepted

You can add it to the file .profile or .bashrc or your current shell profile file (located in your home directory). Then, each time you open your shell it will be loaded.

To change the environmental variable "permanently" you'll need to consider at least these situations:

  1. Login/Non-login shell
  2. Interactive/Non-interactive shell

bash

  1. Bash as login shell will load /etc/profile, ~/.bash_profile, ~/.bash_login, ~/.profile in the order
  2. Bash as non-login interactive shell will load ~/.bashrc
  3. Bash as non-login non-interactive shell will load the configuration specified in environment variable $BASH_ENV

    $EDITOR ~/.bashrc

    add lines at the bottom of the file:

     export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib
     export ORACLE_HOME=/usr/lib/oracle/11.2/client64
    

zsh

$EDITOR ~/.zshrc
#add lines at the bottom of the file:  
     export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib
     export ORACLE_HOME=/usr/lib/oracle/11.2/client64

ksh

$EDITOR ~/.profile
#add lines at the bottom of the file:  
     export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib
     export ORACLE_HOME=/usr/lib/oracle/11.2/client64

bourne

$EDITOR ~/.profile
#add lines at the bottom of the file:  
     LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib     
     ORACLE_HOME=/usr/lib/oracle/11.2/client64
     export LD_LIBRARY_PATH ORACLE_HOME

csh or tcsh

$EDITOR ~/.login
#add lines at the bottom of the file:  
     setenv LD_LIBRARY_PATH /usr/lib/oracle/11.2/client64/lib
     setenv ORACLE_HOME /usr/lib/oracle/11.2/client64

If you want to make it permanent for all users, you can edit /etc/profile or /etc/environment.
In this case follow the syntax you see already present in your file.

share|improve this answer
    
This .profile in /etc/ but I don't how to set the variables in this .profile please tell me –  user3021349 Feb 28 at 13:44
3  
.profile is in your home directory not /etc/ –  Kiwy Feb 28 at 13:45
    
How to check this .profile in my home directory?? –  user3021349 Feb 28 at 13:47
1  
[Admin@localhost etc]$ cat ~/.profile cat: /home/Admin/.profile: No such file or directory [Admin@localhost etc]$ –  user3021349 Feb 28 at 13:49
2  
@user3021349 I don't meant to be rude but if you think one second you can also use a different editor you master. :wq is the command to write file and exit in vi don't forget to type esc before –  Kiwy Feb 28 at 13:59
show 8 more comments

To do if for all users/shells, depending on distro you could use /etc/environment or /etc/profile. Creating a new file in /etc/profile.d may be preferable if it exists, as it will be less likely to conflict with updates made by the packaging system.

In /etc/environment, variables are usually set with name=value, eg:

ORACLE_HOME=/usr/lib/oracle/11.2/client64

In /etc/profile, you must use export since this is a script, eg:

export ORACLE_HOME=/usr/lib/oracle/11.2/client64

Same goes for a file under /etc/profile.d, there also may be naming restrictions which must be met for the file to work. On Debian, the file must have the extension .sh (although does not need a bang line or executable permissions since it is sourced). check your distro documentation or look at the /etc/profile script to see how these files are loaded.

Note also though that setting LD_LIBRARY_PATH permanently is potentially problematic, including being a security risk. As an alternative, I would suggest finding some way to prepend the LD_LIBRARY_PATH to the start of the command line for each program that needs it before running. Eg:

LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib myprog

One way to do this is to use a wrapper script to run the program. You could give this the same name as your program and put it in /usr/local/bin or anywhere that appears before the location of your program in PATH. Here is an example script (don't forget to chmod +x the script):

#!/bin/sh
LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib /real/location/of/myprog "$@"
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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