Boss lesson · Unit 03
Command not found
Environment variables and PATH, ~/.bashrc, then services with systemctl
What you practise
- Environment variables,
export, howPATHis searched,which,~/.bashrc, then services:systemctl status/start/enableandjournalctl -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
deployedCorrect answer
The shell looks for commands only in certain folders
Why
A bare name is not searched for across the whole disk. The shell looks through a short list of folders, and ~/bin is not on it yet. That list is a variable, and you can change it.
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.
echo $HOME # /home/ada
env # print all of them
EDITOR=vim # this shell only
export EDITOR # programs get it tooConcept
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.
# 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.
systemctl status nginx
sudo systemctl restart nginx
sudo systemctl enable nginx
journalctl -u nginx -n 209 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.