151 votes
Accepted

Setting PATH variable in /etc/environment vs .profile

Summary: If you want to add a path (e.g. /your/additional/path) to your PATH variable for your current user only and not for all users of your computer, you normally put it at the end of ~/.profile ...
Byte Commander's user avatar
  • 107k
122 votes
Accepted

How does sudo handle $HOME differently since 19.10?

For years, Ubuntu has shipped a patched version of sudo that preserves $HOME by default. Besides Ubuntu and its derivatives, very few other operating systems (perhaps no others) do this. It has been ...
Eliah Kagan's user avatar
67 votes
Accepted

DEBIAN_FRONTEND environment variable

Simply prepending an apt command with DEBIAN_FRONTEND=something does not persist after the single command to which it is applied. The DEBIAN_FRONTEND options are documented in the Section 7 manual ...
steeldriver's user avatar
62 votes

What does export PATH=something:$PATH mean?

What is this "export" phrase at the start? export is a command (more precisely it's a Bash builtin, i.e. it's not an executable present in PATH, it's a command that Bash has built-in in itself). ...
kos's user avatar
  • 35.9k
61 votes
Accepted

How to permanently set an environment variable

Open a terminal window with Ctrl+Alt+T. Open the file for editing with gedit ~/.profile Add the command to the bottom of the file. Save and close gedit. Log out and log in again.
Gunnar Hjalmarsson's user avatar
60 votes

How do I set environment variables?

To set permanent environment variables in latest Ubuntu versions (from 14.04 and above) add the variables to /etc/environment. For that follow the below instructions, Open the terminal and run sudo -...
Kasun Siyambalapitiya's user avatar
57 votes
Accepted

Environment variables are not accessible in bash script

That's because the HADOOP_HOME variable isn't exported: $ cat foo.sh #!/bin/bash echo "HADOOP_HOME: $HADOOP_HOME" $ HADOOP_HOME=/home/me/dist/hadoop $ echo $HADOOP_HOME /home/me/dist/hadoop $ foo....
terdon's user avatar
  • 101k
49 votes
Accepted

How to save a frequently used SSH host for access via terminal?

Environment variables are for the purpose of communicating information to multiple commands/processes that you start in shell that commands or processes expect to be there in the environment. Usually ...
Sergiy Kolodyazhnyy's user avatar
47 votes

Setting PATH variable in /etc/environment vs .profile

This answer is mainly about the order in which environment variables like PATH are assigned when specified in different configuration files. I do also cover where you should usually set them, but the ...
Eliah Kagan's user avatar
42 votes

What is the $DISPLAY environment variable?

The existing answers fail to address the broader picture. If you are not using a graphical environment (i.e. you are logging in on the system console with no windows etc; or you are logging in ...
tripleee's user avatar
  • 1,464
30 votes
Accepted

Can I access the originating $USER variable from within a script run with `sudo`?

Use the SUDO_USER environment variable instead of USER. sudo places the name of the user who ran it in the SUDO_USER environment variable: ek@Io:~$ sudo sh -c 'echo $USER' [sudo] password for ek: ...
Eliah Kagan's user avatar
29 votes

How can I reset $PATH to its default value in Ubuntu?

You can find it on /etc/environment: $ /usr/bin/cat /etc/environment PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games" So, just source it: $ source /...
Manuel Jesus Rodriguez's user avatar
28 votes

What does export PATH=something:$PATH mean?

https://help.ubuntu.com/community/EnvironmentVariables will probably help you. Also man bash may be very helpful with understanding how that works (at least in Bash) Anyway - as for PATH= you're ...
Jacek's user avatar
  • 1,911
27 votes

Why isn't .profile sourced when opening a terminal?

I found I had to edit the Default profile. In the terminal, click Preferences > Profiles > Edit > Command > Run command as login shell Afterwards new terminals would source .profile script.
Billious's user avatar
  • 371
26 votes

Setting global environment variable for everyone

TL;DR These config files whether global (/etc/environment, /etc/profile) or user-specific (~/.profile, ~/.bashrc) only get processed on next login/session. The global files apply to all users (not ...
mattpr's user avatar
  • 451
21 votes
Accepted

I permanently changed my PATH variable by mistake, and I am unable to login now. How to change my PATH variable to default?

/usr/bin/sudo /bin/nano /etc/environment
Gunnar Hjalmarsson's user avatar
20 votes
Accepted

Background not changing using gsettings from cron

Editing gsettings from cron; missing environment variable If you run the script from your own environment (e.g. from a terminal window or from Startup Applications), a number of environment variables ...
Jacob Vlijm's user avatar
  • 83.7k
20 votes
Accepted

Run a Command-line Program with an Environment Variable

If you want only mpv to be affected, just alias it: alias mpv='DRI_PRIME=1 mpv' You can add this to ~/.bashrc or ~/.bash_aliases.
muru's user avatar
  • 198k
19 votes
Accepted

How to set LD_LIBRARY_PATH permanently?

You just need to add the following line to your ~/.bashrc file: LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/home/lclab/installed/boost/boost_1_65_0:/home/lclab/installed/rdkit/rdkit-Release_2016_03_1/lib:/...
dessert's user avatar
  • 40k
19 votes
Accepted

How do I carry my variables from a Bash script into a Perl one?

Making variables available to child process in shell script can be done either by exporting variables export foo=bar Or by calling program with variables prepended foo=bar ./my_prog.pl In either ...
Sergiy Kolodyazhnyy's user avatar
18 votes

What is the PATH environment variable and how do I add to it?

Shell environment variables are used for several purposes, from storing data, storing software configurations, set terminal settings, and changing shell environment. The environment variables are ...
eGhoul's user avatar
  • 537
18 votes
Accepted

bash -c "v=value; echo $v" displays nothing

There are two shells involved here: The calling shell, the interactive shell from which you are running this The non-login, non-interactive shell, spawned by bash -c Now, the problem is, within ...
heemayl's user avatar
  • 91.7k
18 votes
Accepted

Is "LD_LIBRARY_PATH" a security risk?

This is not a security risk at all, because you can always only set environment variables for your current environment (e.g. current Bash session) and, using the export command, its child environments ...
Byte Commander's user avatar
  • 107k
17 votes

How to see time stamps in bash history?

Changing HISTIMEFORMAT didn't work for me, because I'm using zsh. If you want to make it work with zsh, you just have to type : history -i
Jack''s user avatar
  • 271
17 votes

Dollar sign in environment variable's value

Your example does not illustrate your question. $ toto="somevalue" $ MY_VAR="$toto" $ echo $MY_VAR somevalue $ To do what you asked, you'd need: MY_VAR='$toto' or MY_VAR="\$toto" Can't tell for ...
Gunnar Hjalmarsson's user avatar
17 votes

What does C in LC_ALL=C mean?

C stands for the C programming language. It is a synonym for the POSIX locale. See http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap07.html#tag_07_02 The POSIX locale can be ...
user4556274's user avatar
  • 4,867
17 votes
Accepted

What does the export PATH line in .bashrc do?

To recap everything mentioned in this question, The export part The export line means that the variable that you declare after it will be accessible to child processes. In other words, processes will ...
TheOdd's user avatar
  • 3,002
17 votes
Accepted

Where is this environment variable set?

For bash run: PS4='+$BASH_SOURCE> ' BASH_XTRACEFD=7 bash -xl 7> /tmp/mylog then use grep "http_proxy=" /tmp/mylog to search for it. You can also limit the search to /home and /etc ...
Ravexina's user avatar
  • 55.7k
17 votes
Accepted

PATH=$PATH:`pwd` - What happens when this command is executed?

If you execute the command in your question, you should get an error message: $ PATH =$PATH:`pwd` bash: PATH: command not found If the space is a typo, and you actually run this: PATH=$PATH:`pwd` ...
terdon's user avatar
  • 101k
16 votes
Accepted

How to get the value of an exported variable in the console

To get the value of VARIABLE you can use echo $VARIABLE The quotes don't survive though $ COMP_WORDS="you said what?" $ echo $COMP_WORDS you said what? Unless you quote them... $ quote='"2b || !...
Zanna's user avatar
  • 70.4k

Only top scored, non community-wiki answers of a minimum length are eligible