Setting up your path:
To see what your Path actually is use:
echo $PATH
I set that as an alias:
alias path="echo $PATH"
The $Path is actually set in multiple places. And if you just set the path:
export PATH=foo
that will actually completely replace the current path with “foo”. So you need to add the old path onto the new path:
export PATH=$PATH:foo
That puts foo on the end; meaning that a program located in foo will be found after the system has gone through the entire rest of the Path. If you want your program (located in foo) to be found first then:
export PATH=foo:$PATH
So order is important.
Where to put it?
System-wide the Path is set in a bunch of files located in /etc and it’s subs. As a general rule, you will never need to mess with those. That is the base Path you will be adding to whatever you do.
The 2 files you’ll be working with will be
~/.bash_profile
~/.bashrc
Bash_Profile is only read once - when you log in. So anything set there is set until you log out and log in again.
Bashrc is read every time you open a terminal window. So you could have multiple terminal windows open, each loading a different bashrc.
With that in mind, you would generally set your Path and other environment variables in Bash_Profile (~/.bash_profile). Then you can muck around in your terminal of choice as much as you want.
So here as an example is my current .bash_profile:
# .bash_profile
# User specific environment and startup programs
AppImages=$HOME"/Apps/AppImages"
Scripts=$HOME"/Apps/Scripts"
#Needed for HUGO
#------------------------
Golang="/usr/local/go/bin"
DartSaSS=$HOME"/.local/bin/dart-sass"
# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi
# set PATH so it includes Go programming Language
if [ -d "$Golang" ] ; then
PATH="$Golang:$PATH"
fi
# set PATH so it includes Dart-Sass
if [ -d "$DartSaSS" ] ; then
PATH="$DartSaSS:$PATH"
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
PATH="$HOME/.local/bin:$PATH"
fi
# set PATH so it includes user's AppImages if it exists
if [ -d "$AppImages" ] ; then
PATH="$AppImages:$PATH"
fi
# set PATH so it includes user's Scripts if it exists
if [ -d "$Scripts" ] ; then
PATH="$Scripts:$PATH"
fi
export PATH
Not the prettiest, but it works. If you’ll notice, I set up variables (!) for each entry I wanted to add to my path. Which makes it real easy to change things around if I want to reorganize (not saying I’m OCD + chaos or anything…)
This is also why (when you asked about programming in the other thread) I said to learn bash. Because .bashrc, .bash_profile, .bash_aliases are all just bash scripts.
Which means when you load them into an editor like nano, kwrite, kate, micro, etc you’ll get syntax highlighting.
Does this help?
System-wide (for all users) it’s set in a bunch of files in /etc.