An surroundings variable comprises a worth, this is used to switch the behaviors of the processes at run time.
Similar to the opposite working programs, we will additionally set the surroundings variables on a Ubuntu formula.
You can set the surroundings variables in three ways:
- Using the export command
- Using /and so on/surroundings report
- Adding shell script underneath /and so on/profile.d/ listing
Now we can speak about the above learn how to set surroundings variables on Ubuntu programs one after the other.
1. Using the export command
You can use the export command at the terminal to set the surroundings variables briefly. That variable shall be available at the identical terminal most effective. Once you shut the terminal the variable shall be destroyed.
To set the surroundings variable, run:
To print the MY_ENV surroundings variable, kind:
2. Using /and so on/enviroment report
/and so on/surroundings is a system-wide configuration report used for environment the surroundings variables. It isn’t a shell script, it is composed of the task expressions, that set the surroundings variables one in step with line.
sudo vim /and so on/surroundings
/and so on/surroundings
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin" JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 MY_HOME="/home/tecadmin"
You can set a couple of surroundings variables on this report. Each surroundings variable will have to be in a separate line.
During the formula reboot, the surroundings variable written on this report will routinely be assigned and available system-wide.
3. Using /and so on/profile.d/*.sh recordsdata
You too can create a shell script underneath the /and so on/profile.d listing. During the consumer login /and so on/profile script is carried out. Tha additionally carried out the entire shell scripts (recordsdata with .sh extension) underneath /and so on/profile.d listing.
Let’s create a shell script /and so on/profile.d/custom-env.sh and set the surroundings variables the usage of export command.
sudo vim /and so on/profile.d/custom-env.sh
Set the surroundings variables like:
/and so on/profile.d/custom-env.sh
export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64 export JRE_HOME=/usr/lib/jvm/java-17-openjdk-amd64 export MY_ENV="value1"
The subsequent time the consumer logged in will routinely set the surroundings variables. You can print the worth of our environment variable the usage of the echo command.
echo $MY_ENV value1
This instructional will provide you with the main points of putting in place the surroundings variables at the Ubuntu formula. These surroundings variables are very useful to switch the run time behaviors of processes.
I’m hoping this instructional helped you with the elemental figuring out of making surroundings variables on Ubuntu and Debian programs. Please supply your treasured ideas within the feedback and do percentage this text with the social platform.