How to make exports permanent?

0225

To make environment variable exports permanent in a Bash shell, you need to add them to a shell configuration file that is executed whenever a new shell session starts. Here’s how to do it:

Steps to Make Exports Permanent

  1. Choose the Right Configuration File:

    • For user-specific settings, you typically use:
      • ~/.bashrc: For interactive non-login shells.
      • ~/.bash_profile or ~/.profile: For login shells.
    • For system-wide settings, you can use:
      • /etc/profile: For all users.
      • /etc/bash.bashrc: For all users in non-login shells.
  2. Open the Configuration File:
    Use a text editor to open the appropriate file. For example, to edit ~/.bashrc, you can use:

    nano ~/.bashrc
  3. Add the Export Command:
    At the end of the file, add your export commands. For example:

    export MY_VAR="Hello, World!"
  4. Save and Exit:
    Save the changes and exit the text editor. In nano, you can do this by pressing CTRL + X, then Y, and Enter.

  5. Apply the Changes:
    To apply the changes immediately without restarting the terminal, run:

    source ~/.bashrc

    or, if you edited ~/.bash_profile:

    source ~/.bash_profile

Example

Here’s a complete example of making an export permanent:

  1. Open ~/.bashrc:

    nano ~/.bashrc
  2. Add the export line:

    export MY_VAR="Hello, World!"
  3. Save and exit, then apply the changes:

    source ~/.bashrc
  4. Verify the variable is set:

    echo $MY_VAR

Summary

  • Add export commands to ~/.bashrc or ~/.bash_profile for user-specific variables.
  • Use source to apply changes immediately.
  • For system-wide variables, modify files in /etc/.

If you have any further questions or need clarification, feel free to ask!

0 Comments

no data
Be the first to share your comment!