Home >Common Problem >How to set the path environment variable
How to set the path environment variable: 1. In Windows system, open "System Properties", click the "Properties" option, click "Advanced System Settings", in the "System Properties" window, select the "Advanced" tab , then click the "Environment Variables" button, find and click "Path" to edit and save; 2. For Linux systems, open the terminal, open your bash configuration file, and add "export PATH=$PATH: file path" at the end of the file Just save; 3. For MacOS system, the operation is the same as above.
Setting environment variables is a common task in the operating system, which allows you to access specific programs or directories in the operating system. In operating systems such as Windows, Linux, and MacOS, there is the ability to set environment variables. Below, I will explain in detail how to set the PATH environment variable in Windows, Linux and MacOS systems.
Set the PATH environment variable in the Windows system:
Open "Computer" and enter "System Properties" in the window address bar (or press the Win Pause/Break key) , click the "Properties" option.
In the newly opened window, click the "Advanced System Settings" link.
In the pop-up "System Properties" window, select the "Advanced" tab, and then click the "Environment Variables" button.
In the "System Variables" section, find and click the "Path" variable, and then click the "Edit" button below.
In the pop-up "Edit Environment Variables" window, click the "New" button and add the path to be added to the value of the variable. Use semicolons (;) to separate multiple paths.
After completing the addition, click the "OK" button to save the changes.
Finally, in order for the settings to take effect immediately, you need to restart your command prompt (CMD) or PowerShell.
Set the PATH environment variable in the Linux system:
Open the Terminal.
Use a text editor (such as nano, vim, etc.) to open your bash configuration file, such as nano ~/.bashrc.
Add the following content at the end of the file (assuming your path is /home/user/mybin):
export PATH=$PATH:/home/user/mybin
Save and exit the text editor.
In order for the settings to take effect immediately, you need to run the following command to make the configuration file take effect: source ~/.bashrc.
Set the PATH environment variable in MacOS system:
Open Terminal.
Use a text editor (such as nano, vim, etc.) to open your bash configuration file, such as nano ~/.bash_profile.
Add the following to the end of the file (assuming your path is /Users/username/mybin):
export PATH=$PATH:/Users/username/mybin
Save and exit the text editor.
In order for the settings to take effect immediately, you need to run the following command to make the configuration file take effect: source ~/.bash_profile.
Whether it is in Windows, Linux or MacOS systems, the main goal of setting the PATH environment variable is to easily access specific programs or directories in your system. Please note that there may be some differences between different operating systems and methods, but the basic concepts and steps are similar. Please be careful when performing these operations to avoid problems that may result from misoperation.
The above is the detailed content of How to set the path environment variable. For more information, please follow other related articles on the PHP Chinese website!