To create a new environment variable in Linux, you can use the export command in the terminal. Here’s how to do it:
-
Open a terminal.
-
Use the export command:
export VARIABLE_NAME="value"Replace
VARIABLE_NAMEwith your desired variable name andvaluewith the value you want to assign.
Example:
export MY_VARIABLE="Hello, World!"
- Verify the variable:
You can check if the variable is set by using:echo $MY_VARIABLE
Making it Permanent:
To make the variable permanent (available in future sessions), add the export command to your shell's configuration file (e.g., .bashrc or .zshrc):
-
Open the configuration file in a text editor:
nano ~/.bashrc # or ~/.zshrc for zsh users -
Add the export command at the end of the file:
export MY_VARIABLE="Hello, World!" -
Save the file and exit the editor.
-
Apply the changes:
source ~/.bashrc # or source ~/.zshrc
Now, MY_VARIABLE will be available in all future terminal sessions. If you need further assistance, feel free to ask!
