Bitpath

Boss lesson · Unit 03

Command not found

Environment variables and PATH, ~/.bashrc, then services with systemctl

13 exercisesabout 3 min

What you practise

  • Environment variables, export, how PATH is searched, which, ~/.bashrc, then services: systemctl status/start/enable and journalctl -u

Try a question from this lesson

Pick one

You saved a script as ~/bin/deploy. It exists, it is executable, and it runs when you type its path. Why does plain deploy fail?

$ ls -l ~/bin/deploy
-rwxr-xr-x 1 ada ada 48 deploy
$ deploy
bash: deploy: command not found
$ ~/bin/deploy
deployed

The ideas

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

The environment

Every process carries a set of named strings, its environment: HOME, USER, PATH and more. Read one with $NAME.

Set a variable with NAME=value, with no spaces around the equals sign. It stays inside your shell until you export it. Exported variables are copied into every program the shell starts.

shell
echo $HOME      # /home/ada
env             # print all of them
EDITOR=vim      # this shell only
export EDITOR   # programs get it too

Concept

Making it stick

A change to PATH lasts only as long as the shell you made it in. Close the terminal and it is gone.

Bash runs the commands in ~/.bashrc each time an interactive shell starts. Put the line there and every new terminal has it.

source ~/.bashrc runs the file again in the shell you already have.

shell
# at the end of ~/.bashrc
export PATH="$PATH:$HOME/bin"

Concept

Services

A service is a long-running background program, such as a web server or a database. On most Linux systems, systemd looks after them.

systemctl status, start, stop and restart act right now. enable is a separate switch: start this service at every boot.

A service's output goes to the journal. Read it with journalctl -u name.

shell
systemctl status nginx
sudo systemctl restart nginx
sudo systemctl enable nginx
journalctl -u nginx -n 20

9 more exercises in the app

  • 2× type the answer
  • 1× fill the blanks
  • 4× multiple choice
  • 1× true or false
  • 1× order the lines

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy