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:
- Login/Non-login shell
- Interactive/Non-interactive shell
bash
- Bash as login shell will load
/etc/profile
, ~/.bash_profile
, ~/.bash_login
, ~/.profile
in the order
- Bash as non-login interactive shell will load
~/.bashrc
- Bash as non-login non-interactive shell will load the configuration specified in environment variable
$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
zsh
$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
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 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.
If you are using mysql/Oracle repos you should select Linux-generic
in the Download MySQL Community Server page for AMI boxes and not RedHat/Fedora packages.
Last time I checked AMI does not run systemd
hence the error. While in past you could somewhat get away with installing RH packages in AMI Linux, nowadays with the convergence of Linux versions to systemd
it is ever more difficult to install foreign packages in distributions which do not support systemd
.
File also a bug/request with Oracle for AMI rpm packages, please.
Check also what versions can you find in AMI repositories, just in case.
Best Answer
It's better to set universal variables by creating scripts in
/etc/profile.d
.You want to create it with an extension of your shell name. For example, if it's
bash
, it will be calledscript.sh
for example.The syntax inside will be:
You will need to start a new shell session to add the variable to your environment which you can do by logging out and back in. It will added for the other users' environments when they do the same or the next time they log in if they aren't currently logged in.
Just a note: you don't actually need the shebang line as it's sourced in according to your shell. I put it in myself sometimes as it's just a force of habit but it doesn't hurt or affect anything. You can leave it out if you'd like.