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 ?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityMy 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 ?
You can add it to the file .profile
or your login shell profile file (located in your home directory).
To change the environmental variable "permanently" you'll need to consider at least these situations:
/etc/profile
, ~/.bash_profile
, ~/.bash_login
, ~/.profile
in the order~/.bashrc
$BASH_ENV
$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
$EDITOR ~/.zprofile
#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
$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
$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
$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 the corresponding files under /etc/
, i.e. /etc/profile
for Bourne-like shells, /etc/csh.login
for (t)csh, and /etc/zsh/zprofile
and /etc/zsh/zshrc
for zsh.
Another option is to use /etc/environment
, which on Linux systems is read by the PAM module pam_env
and supports only simple assignments, not shell-style expansions. (See Debian's guide on this.)
These files are likely to already contain some assignments, so follow the syntax you see already present in your file.
Make sure to restart the shell and relogin the user, to apply the changes.
If you need to add system wide environment variable, there's now /etc/profile.d
folder that contains sh script to initialize variable.
You could place your sh script with all you exported variables here.
Be carefull though this should not be use as a standard way of adding variable to env on Debian.
.profile
in /etc/
but I don't how to set the variables in this .profile
please tell me
– user3021349
Feb 28 '14 at 13:44
[Admin@localhost etc]$ cat ~/.profile cat: /home/Admin/.profile: No such file or directory [Admin@localhost etc]$
– user3021349
Feb 28 '14 at 13:49
:wq
is the command to write file and exit in vi don't forget to type esc
before
– Kiwy
Feb 28 '14 at 13:59
crontab
scripts. None of these locations will be looked up when a crontab
script is running.
– yegle
Mar 1 '14 at 1:04
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 "$@"
environment
file, what causes those to load up? For example, after exiting vi editor (changes written successfully) , I'm expecting to write echo $MY_NEW_VARIABLE
and see it print out - EDIT: I see they're there if I launch a new command shell
– bkwdesign
Jan 22 '16 at 0:28
/etc/environment
, even if I restarted the bash terminal or typed source /etc/environment
. So if you're having issues where the environment variable isn't perpetuating, try rebooting.
– Blairg23
Jan 11 '18 at 1:04
/etc/environment
is not a script, so it cannot be sourced. It's loaded at login time (and a handful of other system events) by PAM, so you can either logout/login or run a new login session in a terminal by $ su <your username here>
to pick up the new values in that isolated session. The values will disappear once you exit, so it's probably less error-prone to just fully logout/login.
– AaronDanielson
Feb 12 '18 at 18:33
when you install oracle, oracle asked that you run some scripts before clicking ok. That script put a dummy setting in the .bash_profile
in oracle user home directory. To see the file, ls -al
will show all hidden files.
type nano bash_profile
to open the file. Make changes to the file to reflect your hostname, and appropriate sid name. check any other settings that need modification. press control x to save and type y when asked if you want to save. Press the return key to save.
Restart the computer. Logging as oracle user. start the database by typing
sqlplus / as sysdba
startup
You don't specify which flavour of UNIX you are using. On FreeBSD (and Net and Open BSD) you can use /etc/login.conf
. Full details in the man page but you can add something like:
:setenv=ORACLE_HOME=/usr/lib/oracle/11.2/client64:
to the default class and it will be set for all users regardless of shell or lack thereof.
There are also PAM modules that can do something similar if you are using PAM. e.g pam_env which reads from /etc/environment
.
/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 '14 at 18:19