How to set up your computer for coding

It takes a lot to get a computer ready to begin writing code, including getting the right applications, packages, testing environments, etc. Here are all the best tools and things you need.

Notes:

  1. The $ does not mean something you should copy, it’s the prompt in your Terminal.
  2. Any line that begins with # is just a comment.
  3. The instructions assume you are using a Mac computer (OS X). Most of the commands below will also work for Linux. But if you’re using a Windows machine, then I really don’t know what you’re doing, sorry.
  4. Some commands below require you to install globally. If your machine won’t allow you because of permissions, preface the command with sudo. For example:
# If this doesn't work:
$ npm install less -g
# try this
$ sudo npm install less -g

However, don’t think of sudo a easy way out. Sudo should always be a last resort


Basic Installs

First install iTerm, a terminal app to use the command line in OSX.

Next, install Xcode from the App Store.

# test Xcode installation
$ xcode-select -p
# you should see /Applications/Xcode.app/Contents/Developer

Install Homebrew, a package manager for OS X

$ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

Basically, by installing Homebrew, “brew” is now a command in terminal. Check to see if the installation is working by running brew doctor

Update Brew

# Check your version of Homebrew
$ brew doctor
# Update if needed
$ brew update

Install Ruby, an interpreted object-oriented scripting language

# Check to see if you already have Ruby
$ ruby --version
# Install Ruby if you don't have it
$ brew install ruby

Once you have Homebrew, you can install pip, which is a tool for installing python packages.

Install Python & Pip

# You should already have Python try:
$ which python
# if you don't see anything then install with homebrew
$ brew install python
$ sudo easy_install pip

Install important Pip packages

# Install virtualenv, used for creating isolated Python environments
$ pip install virtualenv
$ pip install virtualenvwrapper
# to use virtualenv tools, use:
$ source /usr/local/bin/virtualenvwrapper.sh
# Install Fabric, a command line tool for streamlining tasks and SSH
$ pip install Fabric
# Install Grip: "GitHub Readme Instant Preview"
$ pip install grip
# then to preview a file, run $ grip FILENAME.md

Install Django, a web framework for python

$ pip install django
# confirm your Django install
$ python -c "import django; print(django.get_version())"
# CD to where you keep your repositories
$ cd [PATH_TO]/mysites/
# Attempt to run django-admin to create your new project
$ django-admin startproject my_django_app
# It may not work (-bash: django-admin: command not found)
# In which case, symlink your django-admin
# your path to python may be different
$ sudo ln -s /library/Python/2.7/site-packages/django/bin/django-admin.py /usr/local/bin/django-admin.py
$ django-admin.py startproject my_django_app
# confirm installation, you should see a page at 127.0.0.1:8000/
$ cd my_django_app
$ python manage.py runserver
# create a database
$ python manage.py syncdb

Github Setup

Github is basically the de facto tool for maintaining, hosting, deploying, and sharing code. It’s basically the social media for coders, but that would be an understatement. Before beginning, create an account on Github.

Install Git with Homebrew

$ brew install git
# Confirm your installation
$ git --version
# Use your own credentials from your github account creation
$ git config --global user.name "John Smith"
$ git config --global user.email EMAIL@EXAMPLE.COM

To allow your computer to talk to Github, you have to make an SSH Key. That is, every time you push or pull, your computer will authenticate automatically so you won’t have to enter your username/password.

Create SSH Key

$ cd ~/.ssh
# Check to see if you don't already have stuff there
# If you do, open the folder in Finder and move them to a backup
$ ls -lha
# Generate key
$ ssh-keygen -t rsa -C "EMAIL@EXAMPLE.COM"
Generating public/private rsa key pair.
# Press "Enter" here
Enter file in which to save the key (/Users/herereadthis/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase):

You will be prompted to created a password. Some people leave it blank, but I recommend you create one anyway, and make sure it is not the same password as the one to your github account. If the ssh key creation is successful, you’ll see something like this:

Your identification has been saved in /home/demo/.ssh/id_rsa.
Your public key has been saved in /home/demo/.ssh/id_rsa.pub.
The key fingerprint is:
3f:ed:44:4a:27:38:93:67:8c:74:4e:4d:dd:0a:c6:35 EMAIL@EXAMPLE.COM
The key's randomart image is:
+--[ RSA 2048]----+
|      ++  .oo.   |
|      .  o.E     |
|        + .  o   |
|  . 0 = .        |
|    = + = .      |
|   E + = o       |
|    . o S o .    |
|     . ++        |
|                 |
+-----------------+

Copy your new SSH key

$ pbcopy < ~/.ssh/id_rsa.pub

Also, you need to add Github to your ~/.ssh/known_hosts so that the authenticity of github.com can be established.

$ ssh -T git@github.com
# you should get a response that says,
Hi GITHUB_USERNAME! You've successfully authenticated, but GitHub does not provide shell access.
# Another way to ensure everything is okay is to add Git to your Keychain
$ git config --global credential.helper osxkeychain
Add SSH key to Github profile

Add SSH key to Github profile

Go to your Github profile (from the homepage, click “Edit Profile”), choose “SSH Keys,” and click “Add SSH Key”. Choose a name that you can remember and will identify the machine you’re using. Then, in the text area, paste the key that you had previously copied. Success!


Node Package Manager

NPM is another package manager for a lot of very useful Javascript tools. Use Homebrew.

$ brew install node
# check npm install version
$ npm -v
# Troubleshooting - if you can run npm install on a repo becase of permissions, run:
$ sudo chown -R `whoami` ~/.npm

Install very useful node packages

# Install Grunt, an automated JavasScript task runner
$ sudo npm install -g grunt
$ sudo npm install -g grunt-cli
# Bower, a package manager
$ sudo npm install -g bower

For more information on Bower, read the tutorial, “How to manage 3rd party libraries using Bower”.

Install optional node packages

# LESS, a CSS preprocessor
$ sudo npm install less -g
# Jekyll, a website/blogging platform also used on GitHub pages
$ sudo npm install generator-jekyllrb -g

Productivity Shortcuts

Useful Terminal commands

Below are lesser-known terminal commands that are good to know

# Display disc usage information (-h means "human readable")
$ df -h
# Display a summary of your current directory (-s means "summary")
$ du -sh *

Add Bash Aliases

Locate a file at ~/.bash_profile and add the following lines. Basically each “alias” is a shortcut for writing much longer commands. For example, with the following alias, you can just type cfr to fetch and reset the master branch of your repository.

# go up one directory level
alias ..='cd ../' 
# go up two directory levels
alias ...='cd ../../' 
# go to Desktop
alias desk='cd ~/Desktop/'
# make sure you git branch is up-to-date
alias cfr='git checkout master;git fetch --all;git reset --hard origin/master'
# if you keep all your repos in one spot, get to by typing "repo REPO_NAME"
repo() {
	cd MY_GITHUB_FOLDER_PATH/$1
}
# create a directory and move into that directory: "mcd DIRECTORY_NAME"
mcd() {
	mkdir -p $1
	cd $1
}

More to Come: