Joel's dev blog

Editing environment path and adding custom scripts

September 23, 2017

2 min read

How to (copied from linuxconfig)

$ echo $PATH
/home/lilo/bin:/usr/local/bin:/usr/bin:/bin:/usr/games
$ PATH=$PATH:/bin/myscripts
$ export PATH
$ echo $PATH
/home/lilo/bin:/usr/local/bin:/usr/bin:/bin:/usr/games:/bin/myscripts

Checking environment variables

type

env

and it will show you everything.

Where are they stored (copied from unix.stackexchange.com)

System wide

  • /etc/environment: specifically meant for environment variables
  • /etc/env.d/*: environment variables, split in multiple files
  • /etc/profile: all types of initialization scripts
  • /etc/profile.d/*: initialization scripts
  • /etc/bashrc: meant for functions and aliases

User specific

  • ~/.bash_profile: initialization for all interactive (bash-)shells
  • ~/.bashrc: initialization for login (bash-)shells
  • ~/.profile: used for all shells
  • ~/.cshrc, ~/.tcshrc, ~/.zshrc, ~/.tcshrc: similar for non-bash shells

So, if you were to add a path to .profile, add:

export PATH=$PATH:/what/ever/path

You will need to source ~/.profile or restart the terminal to take effect (for whatever reason, restarting the terminal did not work for me). For more, look at the ubuntu official documentation.

Is there a standard place for putting custom scripts?

People say it’s normal to place the scripts in /opt or /opt/bin directory. But the answer to the below post also says we could use /usr/local/bin or /usr/local/sbin (for superuser privileges)

Bonus 1: Differences between /bin, /sbin, /usr/bin, /usr/sbin, /usr/local/bin, /usr/local/sbin

  • /bin : For binaries usable before the /usr partition is mounted. This is used for trivial binaries used in the very early boot stage or ones that you need to have available in booting single-user mode. Think of binaries like cat, ls, etc.
  • /sbin : Same, but for scripts with superuser (root) privileges required.
  • /usr/bin : Same as first, but for general system-wide binaries.
  • /usr/sbin : Same as above, but for scripts with superuser (root) privileges required.

Bonus 2:

I wanted to add all subdirectories of usr/local/bin as environment path, but that’s not what something people recommended. People say it’s dangerous.


Written by Joel Mun. Joel likes Typescript, React, Node.js, GoLang, Python, Wasm and more. He also loves to enlarge the boundaries of his knowledge, mainly by reading books and watching lectures on Youtube. Guitar and piano are necessities at his home.

© Joel Mun 2023