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?
The export variables in the .profile or .bash_profile are available when you start a terminal only and not visible to applications started outside the terminal. Use the /etc/environment to make the variables available to all the applications outside the terminal.
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:
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