Windows:
If you are using Windows, you can follow these steps to add environment variables:
Without PowerToys
- Open the Start menu and search for “Environment Variables” or “Edit the system environment variables.”
- Click on the “Environment Variables” button.
- In the “System Variables” section, click on the “New” button to create a new variable or select an existing variable and click on the “Edit” button to modify it.
- Enter the variable name and its value.
- Click “OK” to save the changes.
With PowerToys
- Open the PowerToys quick access and click on “Environment Variables.”
- Next to “User” click “Add Variable.” If you want to edit an existing variable, click on the “Edit” button next to the variable you want to edit.
- Enter the variable name and its value.
- Click “Save” to save the changes.
You can also refer to the Microsoft documentation for more details: Windows environment variables
macOS and Linux:
For macOS and Linux-based systems, you can typically add environment variables by modifying configuration files. Here’s a general approach:
- Edit the appropriate configuration file using a text editor like “nano,” “vim” or “TextEdit.”
- The file you need to edit depends on your shell (e.g., Bash, Zsh, Fish). Common files include .bashrc, .bash_profile, .zshrc, .profile, or .bash_login.
- The file will typically be located in your home directory (e.g., /Users/username/.zshrc).
- .zshrc is typically the file you want to edit if you are using a Mac.
- Add a line in the file in the following format:
Replace VARIABLE_NAME with the name of the variable you want to set and variable_value with the desired value.export VARIABLE_NAME="variable_value" - Save the changes and exit the text editor.
- To apply the changes, either restart your terminal session or run the command
to reload the configuration file.source <filename>
It’s important to note that different distributions may have slight variations in their configuration files. Therefore, it’s recommended to consult the documentation or community resources specific to your distribution.