Ubuntu modify environment variables

Method 1: Modify the $PATH value directly

  • Enter the following command in the terminal command line mode to modify

  • echo $PATH #View the configuration path of the current PATH

  • export PATH=$PATH:/xxx/xxx Add the path to be configured to PATH, there must be no spaces on both sides of the equal sign

  • After configuration, you can view the configuration results through the first command

Note: It will take effect immediately after the modification. Temporary changes can only be valid in the current terminal window. After closing the current window, the original PATH configuration will be restored.

Method 2: Set by modifying the .bashrc file

  • Enter the following command through the terminal command line mode to open the .bashrc file for setting

  • gedit .bashrc edit .bashrc file

  • Add the following code in the last line of the file

  • export PATH=$PATH:/xxx/xxx #xxx/xxx is the address of the environment variable that needs to be added, and there are no spaces on both sides of the equal sign

Note: You need to use the "source.bashrc" command to make the modification take effect. After modifying the PATH configuration, it will only take effect permanently for the current user

Method 3: Set by modifying the profile file

  • Enter the following command through the terminal command line mode to open the profile file for setting

  • vi /etc/profile edit profile file

  • Add the following code in the last line of the file

  • export PATH=$PATH:/xxx/xxx #xxx/xxx is the environment variable address that needs to be added

Note: You need to restart the system through the "reboot" command to make the modification take effect. After modifying the PATH configuration, it will take effect permanently for all users

Guess you like

Origin blog.csdn.net/baidu_38493460/article/details/130365528