Skip to content

Latest commit

 

History

History
233 lines (133 loc) · 9.16 KB

command-line.md

File metadata and controls

233 lines (133 loc) · 9.16 KB

Command Line & Package Manager

Important: everything in this guide refers to the bash unix shell, available in the terminal/command line on macOS and most Linux systems (see).

Command Line

Setting up your git workspace on command line (Mac/Linux)

  1. Open terminal
  2. Save this file in your home directory as git-completion.bash
  3. Save this file in your home directory as git-prompt.sh
  4. Save this file in your home directory as bash_profile_course

Setting up your bash profile

The bash_profile is located in your home directory.

  • In terminal, type the command cd
  • Type ls -a to view all files (including hidden dot files)
  • If you don't have .bash_profile then rename bash_profile_course to .bash_profile
  • Open .bash_profile with your editor and do the following:

If you already have a file in your home directory named .bash_profile, copy the content from bash_profile_course and paste it at the bottom of .bash_profile.

Otherwise, move bash_profile_course to your home directory and rename it to .bash_profile. If you use Linux, you may need to name this file .bashrc instead of .bash_profile.

Make sure you can start your editor from the terminal

You can do this by either:

  • Check documentation for your editor for example:

    • To open a file in Atom from the command line use atom filename. The Atom menu bar has a command named "Install Shell Commands" which installs the atom and apm commands if Atom wasn't able to install them itself
  • See alias section below

Restart the terminal

You'll need to close and re-open the terminal before all your changes take effect.

Make an 'Alias' (shortcut)

An 'alias' is just a shortcut for executing some command. For example, we can create an alias for a commonly used file or directory. A temporary alias is created from command line and only endures for the current terminal session. A permanent alias is saved within your .bash_profile.

An alias follows the general form:

alias new_name='command to be performed'

Making a Temporary Alias

Lets begin by making a temporary alias to access your documents folder. Using alias we ascribe a particular action to a variable, as below. Make sure that the directory is correct.

alias docs='cd [/Users/YOUR-USER-NAME/documents]'

You should now be able change directory to your documents folder by going to your terminal typing docs and pressing enter.

Making a Permanent Alias

Make an Alias to open your .bash_profile

I'm always forgetting how to locate my .bash_profile, so lets make a permanent alias to open it with ease.

The code below ascribes to the variable bash_profile the command line open with the location of the .bash_profile file.

alias bash_profile='open ~/.bash_profile'

Now you can open your .bash_profile by going to terminal, typing bash_profile and pressing enter.

Make an Alias to Open Your Preferred Text Editor

When you install your editor it may provide you with a terminal shortcut to open it, and to use it to open files/directories. If your editor does not make this available, you can achieve the same by creating an alias.

For example to create an alias to open Sublime, save the following code in your .bash_profile (make sure you use the correct directory).

alias subl="/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl"

Now when you type subl in terminal and press enter you can directly open Sublime. You can also type subl [FILE/DIRECTORY] to open a specific file/directory in Sublime.

Install using a package manager

Instructions for Mac

  1. First you need to install your package manager. Go to the command line and type
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Visit the Homebrew website for more information.

  1. Check if it's installed and working properly by typing brew doctor into the command line.

  2. To check for updates, use the command line prompt brew update.

  3. If you're looking to install graphical apps (e.g. Chrome), you'll need to download Homebrew cask.

brew install caskroom/cask/brew-cask
  1. Installing a graphical app:
  • search for the app using brew cask search name , where name is the name of the app you are looking for.
  • install the app with brew cask install name This will automatically download the app, extract it and install it to your Applications folder.
  • if you change your mind, you can uninstall the application using brew cask uninstall name.
  1. Installing open-source utilities:
  • to search for a utility, type brew search name.
  • to download and install the utility, you'll need to type brew install name.
  • to remove the package later, use brew remove name.

Instructions for Linux

Depending on what base operating system your linux distro uses you will need to install different package manager wrappers. Each OS comes with its own package manager by default however they can be annoying to use, which is why it is common to install a more user friendly wrapper.

Distros such as:

Use the Debian base operating system and have Apt package manager installed, they'll need to use Linuxbrew for package management.

Distros such as:

Use the Arch base operating system and have Pacman package manager installed, they'll need to use either Packer or Yaourt for package management.

Installing for Debian - Linuxbrew

Linuxbrew is a fork of Homebrew, the macOS package manager, for Linux. It can be installed in your home directory and does not require root access. The same package manager can be used on both your Linux server and your Mac laptop.

You may first need to install Ruby as it requires 1.8.6 or newer:

sudo apt-get install build-essential curl file git python-setuptools ruby

The installation script installs Linuxbrew to /home/linuxbrew/.linuxbrew if possible and in your home directory at ~/.linuxbrew otherwise.

Paste at a Terminal prompt:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Linuxbrew/install/master/install)"

Follow the Next steps instructions to add Linuxbrew to your PATH and to your ~/.bash_profile.

If you installed Linuxbrew in /home/linuxbrew/.linuxbrew (recommended):

PATH="/home/linuxbrew/.linuxbrew/bin:$PATH" echo 'export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"' >>~/.bash_profile

If you installed Linuxbrew in your home directory:

PATH="$HOME/.linuxbrew/bin:$PATH" echo 'export PATH="$HOME/.linuxbrew/bin:$PATH"' >>~/.bash_profile

You’re done! Try installing a package:

brew install hello

If you’re using an older distribution of Linux, installing your first package will also install a recent version of gcc.

Use brew doctor to troubleshoot common issues.

Installing for Arch - Packer or Yaourt

Packer and Yaourt is a wrapper for Pacman that allows installing packages from Arch User Repository (AUR). They make life easier by eliminating the need to manually compile packages available on AUR. Once the package is downloaded from git and compiled it can be installed with Pacman like any other package.

Installing Packer

Install required dependencies.

sudo pacman -S wget git expac jshon

Create a temporary directory for the installation.

mkdir packer

Change current directory to the temporary installation directory.

cd packer

Download the package build script from AUR.

sudo wget https://aur.archlinux.org/cgit/aur.git/plain/PKGBUILD?h=packer

Rename the downloaded file.

mv PKGBUILD?h=packer PKGBUILD

Compile the package using PKGBUILD.

makepkg

Install the newly created package.

sudo pacman -U packer-20150808-1-any.pkg.tar.xz

The -U option specifies a package that is not from the Pacman repositories. Check the exact name of the created package with the ls command and replace the name if needed after the -U option.

Navigate out of the temporary installation directory.

cd ..

Clean up by removing the temporary installation directory.

sudo rm -dR packer

Installing Yaourt

Yaourt can be very easy to install using git and AUR!

git clone https://aur.archlinux.org/package-query.git

cd package-query

makepkg -si

cd ..

git clone https://aur.archlinux.org/yaourt.git

cd yaourt

makepkg -si

cd ..