Skip to content

Instantly share code, notes, and snippets.

@JYoung217
Last active February 14, 2019 00:23
Show Gist options
  • Save JYoung217/194c2d880e72778c5994f4a3c6812af2 to your computer and use it in GitHub Desktop.
Save JYoung217/194c2d880e72778c5994f4a3c6812af2 to your computer and use it in GitHub Desktop.
Code Platoon Installfest

CodePlatoon Installfest

What we'll cover

  1. subl / atom / code
  2. Understanding the Unix Environment
  3. Homebrew
  4. sqlite3
  5. postgres
  6. RVM/rbenv
  7. Ruby
  8. gems

subl / atom / code

These are commands that allow you to open a file or directory in your code editor from the command line. These are all symbolic links so that you can run subl some-filename.txt / atom some-filename.txt / code some-filename.txt

  • Sublime: After installing Sublime Text 3 from the website and putting it in your applications folder, run the following command in your terminal: ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
  • Atom: Click Atom >> Install Shell Commands and you should be set
  • VSCode: Follow the instructions here

Homebrew

First let's ensure we've installed homebrew correctly.

$ which brew
/usr/local/bin/brew

If you don't see this, run:

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

Homebrew is going to do a lot of work for us, so always ensure that it's up-to-date and that it's healthy.

$ brew update

and

$ brew doctor

brew doctor may tell you a lot of stuff… you'll want to read through each item, and attempt to resolve the issue for Homebrew. Warnings are good to read but are not mandatory to fix. We're ideally shooting for a message like this:

$ brew doctor
Your system is ready to brew.

Adjusting $PATH for Homebrew

Homebrew is going to be installing packages and tools for us, so we need to make sure that when possible, our system is using homebrew's installed packages.

We'll start by inspecting our path

$ echo $PATH | tr : '\n'
/Users/jon/bin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin

Ensure that /usr/local/bin comes before /usr/bin and /bin.

If it doesn't, open $HOME/.bash_profile using Sublime Text and add the following:

export PATH="/usr/local/bin:$PATH"

Also check out the rbenv documentation.

Installing sqlite3 using Homebrew

$ brew install sqlite3

Installing postgres using Homebrew

$ brew install postgres

postgres is a piece of software that requires a server to interface with. It's easiest to let OS X's launchd utility keep this server running, otherwise we'd have to restart it every time it died or our machine rebooted.

$ ln -sfv /usr/local/opt/postgresql/*.plist ~/Library/LaunchAgents
$ launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
$ which postgres
/usr/local/bin/postgres
$ which psql
/usr/local/bin/psql

Now Homebrew will keep our postgres server alive so that we can just develop awesome apps and not worry about the database. Let's ensure that we have a server running. To do that we'll use ps:

$ ps aux | grep postgres

### As long as anything shows up on the screen, you will be fine. You don't need to match up with my output below

jon              444   0.0  0.0  2439324    148   ??  Ss   13Feb14   0:02.33 postgres: stats collector process
jon              443   0.0  0.0  2443176    624   ??  Ss   13Feb14   0:02.44 postgres: autovacuum launcher process
jon              442   0.0  0.0  2443044     80   ??  Ss   13Feb14   0:03.72 postgres: wal writer process
jon              441   0.0  0.0  2443044    132   ??  Ss   13Feb14   1:29.90 postgres: writer process
jon              440   0.0  0.0  2443044    136   ??  Ss   13Feb14   0:00.14 postgres: checkpointer process
jon              403   0.0  0.0  2443044     68   ??  S    13Feb14   0:00.40 /usr/local/opt/postgresql/bin/postgres -D /usr/local/var/postgres -r /usr/local/var/postgres/server.log
jon             6469   0.0  0.0  2432768    600 s000  R+    5:42PM   0:00.00 grep postgres

The process with pid (process id) #403 is our server process. You can see here what executable (the full path) is running, where the data file is (ie. /usr/local/var/postgres), and where we can find the logs (ie. /usr/local/var/postgres/server.log).

Finally, create a default database and test our postgres client, psql.

createdb $USER
psql $USER # this is a sql console for interacting with a postgres database
enter `\q` to quit

Managing Ruby Installations

rvm, rbenv, or chruby? There are a number of different popular tools for installing/managing/using different versions of ruby on your machine. We are going to use rbenv for our classes.

Install rbenv using Homebrew

brew install rbenv will have homebrew install rbenv

rbenv init will initialize rbenv in your current shell

Now that rbenv is installed, we need to configure our environment to use it. The instructions say that we need to add the following to our $HOME/.bash_profile:

subl ~/.bash_profile

When Sublime opens, add the following line of code in it:

if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi

Then reload your bash profile so all the changes are kept with you:

source ~/.bash_profile

Usage:

$ rbenv install --list      # will list all of the Rubies ruby-build can install
$ rbenv install 2.6.1       # will install ruby 2.6.1. This will take a while.
$ rbenv versions            # will list the Rubies you already have installed, should have `* system` selected
$ rbenv global 2.6.1        # will set the global/shell/local ruby
$ rbenv versions            # should see 2.6.1 selected
$ rbenv rehash              # tells your shell to use the new version of rbenv

Verifying your Ruby Manager

which rbenv
$HOME/.rbenv/bin/rbenv
OR
/usr/local/bin/rbenv

Ruby

Let's make sure you're NOT using the system ruby.

$ which ruby
/Users/jon/.rbenv/shims/ruby

If this says /usr/bin/ruby, then we need to get your ruby installed via a ruby version manager. I suggest rbenv (see above).

If you're using rbenv, run this:

$ rbenv which ruby
/Users/jon/.rbenv/versions/2.5.0/bin/ruby

Same as above, it should not say /usr/bin/ruby. If it does, then install a ruby (via rbenv), then set it as your default ruby (rbenv global <ruby version you installed>).

Gems

Most gems are fairly easy to install, but there are a few that we use at CodePlatoon that can be problematic (usually the ones with native dependencies). Let's start by verifying that the gem executable is installed via a ruby version manager.

$ which gem
/Users/jon/.rbenv/shims/gem

You'll notice that gem is in the same directory as ruby (from above). This is good. If they aren't in the same place, that's usually a problem. If it's /usr/bin/gem that's an issue.

If you're using rbenv, run:

$ rbenv which gem
/Users/jon/.rbenv/versions/2.5.0/bin/gem

Again, just like ruby, this shouldn't say /usr/bin/gem. It should also be in the same location as when you ran rbenv which ruby.

Let's also update rubygems.

$ gem update --system
# This may take a while

Alright, ON TO THE HARD GEMS! First, bundler.

gem install bundler
rbenv rehash        // if you're using rbenv, which you should be

And the rest:

gem install sqlite3 pg nokogiri
# Here, you're installing 3 gems! This is going to take a while...

Install git using Homebrew

$ brew install git

Ensure we're using git from homebrew:

$ which git
/usr/local/bin/git

Question: OS X ships with git isn't that good enough? Answer: It might be, but it's likely out of date, and you won't benefit from new tools and developments. git is a tool we'll use frequently, so installing it and keeping it up to date is akin to a chef keeping their knives sharp. Up-to-date tools are one of the marks of a craftsman; strive to be a craftsman.

There are a few steps you should configure so git works well. The first, is setting up a global .gitignore file:

touch  ~/.gitignore_global

Using Github's Gitignore Guide, we are going to set up the file for our computer:

$ git config --global core.excludesfile '~/.gitignore_global' 

Next, You'll want to get your gitconfig setup to recognize your github credentials:

  1. Set up your command line Git username
  2. Set up your command line Git user email
  3. Cache your Github password so that you don't have to type it in every single time you push to Github

Finally, ensure that Sublime is your global text editor for all things Git:

$ git config --global core.editor "subl -n -w"

Confirm gitconfig is set up, both for your username/email and gitignore by running git config --global -l You should see that your username, email, gitignore, and editor are all listed.

Install bash using Homebrew

$ brew install bash

To use this new version of bash, we'll need to add it to /etc/shells. /etc/shells is owned by the root user (verify using ls -la /etc/shells), so we'll need to use sudo to write to it.

$ subl /etc/shells

Add /usr/local/bin/bash to the last line and save.

Now we need to change our shell command:

$ chsh -s /usr/local/bin/bash

All set. We can launch a new teminal window and verify our setup.

$ bash --version
@KaraAJC
Copy link

KaraAJC commented Sep 11, 2017

  • add this macOS gitignore link to Git Config Process
  • ensure all terminal commands start with $:> to emulate what is set default
  • there was some kind of rearranging of steps that was going to happen
  • put the git config check command onto it's own line

@JYoung217
Copy link
Author

put in sublime user preferences

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment