I was using the command export, but it looks that after some time the set variables disappears. What is the easiest way of setting an environment variable forever?
Super User is a question and answer site for computer enthusiasts and power users. It only takes a minute to sign up.Sign up to join this community
According to the version of Linux, and assuming the standard bash shell is used, the user in question will have a .profile or .bash_profile file in their home folder (it's the latter in Ubuntu). You can use your favourite editor to add the variable definition there - for example:
# .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin export PATH
# .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=$PATH:$HOME/bin MYVARIABLE=THISVALUE export PATH MYVARIABLE
The export command pushes the variable out into the child environment so it's available to other scripts and processes. You don't have to pile up the variable names behind a single export command, you can also do the whole definition and export in one go eg:
Global variables for everyone can be set in a similar way in /etc/profile