How to set environment variable without rebooting Ubuntu?
Solution 1
Strictly speaking you can't since that file is only read on login, by pam_env. You can however source it in your current shell to read in the values.
$ . /etc/environment
Solution 2
You can add to your $PATH variable directly like this:
export PATH=$PATH:/the/dir/you/want/to/add
Then, edit /etc/environment.
An alternate method would be to still export as I showed above, but then to add the entry to your ~/.bashrc file (if using BASH shell).
echo "export PATH=$PATH:/the/dir/you/want/to/add" >> ~/.bashrc
source ~/.bashrc
EDIT: Exporting your $PATH in your ~/.bashrc file rather than /etc/environment keeps you from needing to elevate permissions to edit a "global" (system) config file and also keeps other users (if you have any on your system) from having that path auto-added on account creation.
Related videos on Youtube
dgrgge4
Updated on September 18, 2022Comments
-
dgrgge4 over 1 year
Problem: During Android development, in order to add ADB path to environment variable; I did following things:
gedit /etc/environment
- Added my desired path in the file such as:/media/Software/00.AndroidLinux/ADT/sdk/platform-tools
What I noticed is that adding path to the file has no effect to
$PATH
until I reboot my Ubuntu.My question is: How can I add path to
/etc/environment
variable, so that I can work with my modified$PATH
, and without restarting Ubuntu?