Introduction
Created by Christopher Lawrence GS '24
Down the stretch they come! We only have one more tutorial after today. In this tutorial we are going to learn how to install new programs and utilities using the command line. Many of the programs that we have covered so far come pre-installed with Linux or MacOS. However, that is not always the case. If you come across a command on StackOverflow or some other tutorial and aren't sure if you have the program already installed run the command anyway and you may be prompted with how to install it.

Just because we know how to install a program doesnt mean we will be able to install it. I know it seems a little counterintuitive but stay with me here. We cant have everyone and their Aunt Kim going around installing their own programs and applications all whilly nilly. That would cause absolute chaos. So to prevent this exact scenario the progenitor of Linux (Linus Torvald) created permissions. Only certain users can interact with certain parts, files, and folders of the computer, preventing Aunt Kim from screwing everything up. But this can prevent Us (the User) from installing programs. However there is a way to get around this, and that is the sudo (sue-dough) command.
sudo
Sudo, the answer to all life's problems. It stands for "super user do". This command will temporarily allow you to circumvent any access denied screen by running the program with elevated privileges. Compared to logging in as the all powerful root user where one bad typo can erase your computer, sudo is safer and faster. Lets try it out.

Theres not much that can refuse sudo. But to use it you will need to know the password. This password will correspond with the one you use to log into your mac or computer. You will not be able to see what you have entered, so make sure you're typing is correct. Else you may be reported to the head administrator (In this case....its you). sudo also works to remove packages, see below. Now lets utilize this power to install some programs!!

apt-get/dpkg/yum
From the primordial soup of Unix emerged the first operating system, Debian. Debian beget Ubuntu, who beget Linux Mint, who beget Raspbian. All of these operating systems use APT (the Advanced Packaging Tool) to install new programs. Apt provides commands used for most common operations: Searching repositories, installing collections of packages and their dependencies, and managing upgrades. APT commands operate as a front-end (User-interaction) to the back-end (database interacting) dpkg utility, which handles the installation of individual files on your system.

apt-get can also be used to update and upgrade packages and complete OS installations as well as removing packaged.

So learn apt-get and use this to your advantage.
package handlers/manager
A package manager is a collection of software tools that automates the process of installing, upgrading, making, removing, compiling, and almost everythingelse-ing new software and programs onto your computer. Most likely, you are already familiar with a package manager. For example, apt (above) is a command line package manager, and so is the application store on MacOS.

Side Note: Snap/Snapplications
Snap is a software packaging and installation system that allows developers to publish software directly to users. All software must undergo automatic testing before being uploaded to a central repository.. the Snap Store

These packages can also be installed from the command line. And when you double click through the GUI the process will be executed through the command line anyway.

Side Note: Xcode on MacOS
Xcode is a collection of command line tools and utilities, which creates a Unix-Linux style environment on your Mac. This is available (free) via the Mac Application Store and gives users the ability to develop their own applications and programs. Git and make are two programs briefly covered later in this tutorial that come included with Xcode.

brew and brewcask
Similar to snap and the snap store, brew and brewcask allows users to install new programs in one line of code. Hooray! No more dragging and dropping .dmg files or unpacking, god forbid tarring and un-gzipping. To install brew on your machine, use one of the following lines.
Mac OS
sudo apt get upgrade or update your curl, if the script below fails
/bin/bash -c "$(curl -fsSL [<https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh>](<https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh>))"
Linux-distibutions
sudo apt-get install build-essential curl file git
/bin/bash -c "$(curl -fsSL [<https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh>](<https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh>))"

Once finished, run the following commands to finish the linux installation. If on MacOS this should not be needed.
test -d ~/.linuxbrew && eval $(~/.linuxbrew/bin/brew shellenv)
test -d /home/linuxbrew/.linuxbrew && eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)
test -r ~/.bash_profile && echo "eval \\$($(brew --prefix)/bin/brew shellenv)" >>~/.bash_profile
echo "eval \\$($(brew --prefix)/bin/brew shellenv)" >>~/.profile
For more help and general information, use the following link (https://docs.brew.sh/)
Brew is nice because it installs without root access and every installed package is cleanly placed into a single location, instead of having stray files all over your system. With Brew we can quickly install programs on the fly and personalize our command line environment with the tools we need to accomplish any project.

git clone
Another way to install programs and packages and download data is through git clone. Git clone is a command line tool used to create a copy of a specific program, database, or file, and download it to your computer. To download these files or repositories, our designated repository has to be located on github. Lets try it out. Go to https://github.com/git-learning-game/oh-my-git and look for the green code tab. Click on it, copy the link, then go to the terminal.

This will download a copy of this repository onto your computer. Now that we have it, we can return the the github page and look for readmes and info on how to install.
Side Note: Github and Git further
Git is an open source project originally developed by.....also Linus Torvalds. Linus and other Linux developers wanted a file management system that could apply and update all associated metadata, files, and folders with a project at the same time. Their solution was git.

Git (which means "unpleasant person" in British English slang) is self described as "the stupid content tracker". The read-me file of the source code elaborates further: "git" can mean anything, depending on your mood. The fact that it is a mispronunciation of "get" may or may not be relevant. It goes on, but we will spare you.
Git (pronounced "get", or in a southern accent "geet") is software for tracking changes in any set of files, usually used for coordinating work among programmers collaboratively developing source code during software development.
If more interested in using version control and not saving a document final_final_final_version3_final.ppt. Git is just the thing. To learn more about git and how to become a bonafide version control master, I suggest playing around with "oh my git". We downloaded the game earlier! More instructions can be found here (https://blinry.itch.io/oh-my-git)

Oh my git is a free to play game that teaches you the ins and outs of version control. Be warned there is a learning curve.
Package Managers et. al
There are other package managers out there: here is a short non exhaustive list that you should explore on your own time. pip, anaconda, Conda, pacman, Easyinstall, npm, Pear, Docker, Snappy, LinuxBrew, MacPorts, and much much more.
Often while installing programs from github or some other remote source we may run across several problems. We may not have all the software we need installed. We might have other programs that dont play well with what we want to install. Its at times like these, that compiling and building a software from the ground up may be beneficial. The goal of a good package manager is to prevent this from happening, but its good practice to know how this is done. To do this, we will use make.
make
make, (formally known as GNU make) is a tool to create executable programs from source code. make is the de-facto tool for building executable programs from source code in the world of open source.

make enables, us users to build executable programs without knowing the nitty gritty technical details of how to build them. All the details are listed in the "makefile" so the process becomes repeatable and it deletes any intermediate files, keeping the environment clean! You should already have make installed but check to make sure and if not, install it. Once installed, we can compile our first program.
make is agnostic when it comes to programming languages. So for the purpose of this tutorial we are going to write a simple program in C.
Create a file called hello.c and paste the following.
// hello.c
#include <stdio.h>
int main() {
printf("Hello, world!\\n");
return 0;
}
Now create a makefile (just called "makefile") and paste this,
all: hello.exe
hello.exe: hello.o
gcc -o hello.exe hello.o
hello.o: hello.c
gcc -c hello.c
clean:
rm hello.o hello.exe
Find these files on the command line and when ready type make and press enter.

An executable file called hello.exe will be generated in the current directory. To execute this file run ./hello.exe. Like so,

Make is one of the most essential tools for linux users and programmers alike. This knowledge of make will help you fix many broken things in your world of linux and on the command line.
This completes this tutorial!
In the next tutorial, we will learn how to customize our command line environment, do some scripting using the commands we've learned, get silly, and cross the finish line. See you there!