Three methods for setting environment variables under Linux:
If you want to add a path to $PATH, you can do it like the following Do this:
Environmental variables that work only for the current shell
1. Set in the console, disapproved This way, because it only works on the current shell, changing a shell setting is invalid:
Enter directly into the console: \(PATH=”\) PATH”:/NEW_PATH (Close the shell Path will restore to the original path)
Works for all users Environment variable
2. Modify the /etc/profile file. If your computer is only used for development, use this method, because all users’ shells have the right to use this environment variable. Bring security issues to the system. This is for all users, all shells
vi /etc/profile
Add at the bottom of /etc/profile: export PATH=”$PATH:/NEW_PATH”
Environmental variables that work for the current specific user
3. Modify the bashrc file, this method is more secure , It can control the permission to use these environment variables to the user level, here is for a specific user, if you need to give a user permission to use these environment variables, you only need to modify the .bashrc in the home directory of the individual user The file will do.
vi ~/.bashrc
Add below:
Export PATH=”$PATH:/NEW_PATH”