Environment Variables

Posted by zbrom on June 25, 2021 · 1 min read

This tutorial will help you set environment variables for a particular user. An excellent example of this is mapping your /home/$user/bin to the $PATH variable, allowing the user to execute scripts from the /home/$user/bin from any terminal. Using the /home/$user/bin method is more convenient during development rather than soley copying files over to the /usr/bin folder. Whenever $user is specified in this tutorial, feel free to replace it with your username.

First, ensure you have created a bin folder inside of your home folder.

Edit the .bashrc file in your home folder; open a terminal and type the following.

nano .bashrc

Add the following line of code to your .bashrc file; this will map your ~/bin folder to the $PATH variable.

export PATH=$HOME/bin:$PATH

Sample output of mine:

## ~/.bashrc## If not running interactively, don't do anything[[ $- != *i* ]] && return

alias ls='ls --color=auto'

PS1='[\u@\h \W]\$ '

export PATH=$HOME/bin:$PATH

You can now execute scripts inside of your /home/$user/bin folder from any terminal.

It is also possible to set environment variables for a particular session, by entering the following into a terminal:

export PATH="${PATH}:/home/$user/tmp/usr/bin"

This method will only remain valid until you logoff.

For additional information, please visit the Arch Wiki: https://wiki.archlinux.org/index.php/Environment_Variables

Check out the code section of the site for useful scripts.