How do you create a new environment variable in Linux?

095

To create a new environment variable in Linux, you can use the export command in the terminal. Here’s how to do it:

  1. Open a terminal.

  2. Use the export command:

    export VARIABLE_NAME="value"

    Replace VARIABLE_NAME with your desired variable name and value with the value you want to assign.

Example:

export MY_VARIABLE="Hello, World!"
  1. 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):

  1. Open the configuration file in a text editor:

    nano ~/.bashrc  # or ~/.zshrc for zsh users
  2. Add the export command at the end of the file:

    export MY_VARIABLE="Hello, World!"
  3. Save the file and exit the editor.

  4. 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!

0 Comments

no data
Be the first to share your comment!