To set environment variables in Bash, you can use the export
command followed by the variable name and value.
Here's the general syntax:
export VARIABLE_NAME="value"
For example, to set an environment variable named MY_VAR
with the value Hello World!
, you would run:
export MY_VAR="Hello World!"
You can also set multiple environment variables in a single command by separating them with spaces:
export VAR1="Value1" VAR2="Value2" VAR3="Value3"
To make the environment variables permanent, you can add these export statements to your ~/.bashrc
or ~/.bash_profile
file, so they are loaded every time you start a new shell session.
It's important to note that environment variables set in a shell session are only available within that session and its child processes. If you want to make them available to all processes on your system, you can define them in /etc/environment
or in individual files in the /etc/profile.d/
directory.