In this short tutorial, I’ll show you how to set environment variables permanently in Linux Mint.
Environment variables help programs to find important information and work properly. For example Java programs use JAVA_HOME
.
Step 1: Set environment variables for current session
For tests you can create session variables. The session environment variable is created by writing in terminal:
export RSTUDIO_PANDOC=/usr/lib/rstudio/bin/pandoc
Variable RSTUDIO_PANDOC
is used for RMarkdown.
To use RMarkdown generation outside Rstudio you need to have it set. For example PyCharm you can open the console and run the command above.
If the RMarkdown works properly you can move to the next step and set it permanently.
Step 2: Set environment variables permanently
To set permanent environment variables in Linux Mint follow next steps:
Set ~/.profile variables
- Open a terminal - CTRL+Alt+T.
- Edit file
~/.profile
by
nano ~/.profile
- Add the variable to the bottom of the file:
export RSTUDIO_PANDOC=/usr/lib/rstudio/bin/pandoc
- Save and close nano
- CTRL+x and then y
- Apply changes by:
source ~/.profile
Set ~/.bashsrc variables
- Open a terminal - CTRL+Alt+T.
- Edit file
~/.bashsrc
by
nano ~/.bashsrc
- Add the variable to the bottom of the file:
export RSTUDIO_PANDOC=/usr/lib/rstudio/bin/pandoc
- Save and close nano.
- Apply changes by:
source ~/.bashsrc
~/.bashsrc vs ~/.profile
It depends on your case which one you should use. You can find more information on the link below:
.profile is for things that are not specifically related to Bash
.bashrc is for the configuring the interactive Bash usage
What are the functional differences between .profile .bash_profile and .bashrc
Note you can find more Linux Mint commands and their Windows equivalents here:
Step 3: List all environment variables in terminal
To list all environment variables in Linux Mint you can use the next command:
printenv
The outpus is:
NVM_DIR=/home/user/.nvm
RSTUDIO_PANDOC=/usr/lib/rstudio/bin/pandoc
LANG=en_US.UTF-8
GDM_LANG=en_US
DISPLAY=:0