What is .bashrc?
.bashrc
is a shell script that the Bash shell uses to configure and customize your shell environment. It is typically used to change prompts, set environment variables, define command aliases and define shell functions. Other shells use their own specific dot files.
Where is the .bashrc file located?
The .bashrc
file lives in your home directory. Since it is a dot file (filename begins with a “.”, it is hidden). To see if it exists:
ls -la ~/.bashrc
How do I set environment variables in my .bashrc file?
You can use the .bashrc file to define environment variables like PATH
, LD_LIBRARY_PATH
, PYTHONPATH
, etc. Once you define these variables in the .bashrc
file, your shell would know the paths since .bashrc
is read at every login.
Let’s say you want to use two software from /usr/local/
, CUDA and Eclipse IDE. For this you would define the PATH
variable by adding the following lines to your .bashrc
file:
|
|
Save the file and source it for changes to be applied to the current shell.
source ~/.bashrc
How do I confirm that the environment variable configuration has been applied?
You can confirm by using the printenv
command. The command output should contain the paths you added.
printenv $PATH
/usr/local/eclipse/java/latest/bin:/usr/local/cuda/latest/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin
Where do I add the environment variable settings in the .bashrc file?
You can add these lines at any place in the .bashrc
file, however, note that these variables get built as the shell reads the file.
So, be careful with multiple definitions of the same variable in your .bashrc
file.
I have messed up my .bashrc file. How do I fix it?
You can get a fresh copy of the default .bashrc
file using these commands:
/bin/mv ~/.bashrc ~/.bashrc.backup
/bin/cp ~info/dot.files/.bashrc ~/.bashrc