Skip to content

Instantly share code, notes, and snippets.

@preslavrachev
Last active September 8, 2017 16:11
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save preslavrachev/34820d5a33c9578e53b6 to your computer and use it in GitHub Desktop.
Save preslavrachev/34820d5a33c9578e53b6 to your computer and use it in GitHub Desktop.
Some important steps and tools for setting up a new Mac and making it ready for development (in particular, Java development, but most of the steps matter for others too)

Setting Up a New Mac for Development

Command-Line Utilities

Homebrew

An absolute must. If you have ever worked with apt-get on Ubuntu, you know that it's the absolute developer bliss. Homebrew (or brew for short) is the missing package manager for OSX. Not only does it allow you to install/unisnstall/manage software with a few simple commands, the same way that apt-get does. It allows you to access and install ports of most of the cross-platform utilities that you might be familiar with from Linux, over to OSX.

Installing Brew

Simply open a new terminal and execute the following command:

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

Brew Troubleshooting

Sometimes you might run into problems running Brew. The general advice here is to execute brew doctor and follow the instructions you see there.

Here are a few of the more typical problems that I've personally stumbled upon:

Error: /usr/local must be writable!

This is a quite standard persmissions problem and usually occurs when you update the version of your Mac OS (OSX EL Capitan has been particularly well known for dropping permissions off /usr/local) or a few other system applications.

The solutions to this is to give your user permissions again:

sudo chown -R $(whoami) /usr/local

UPDATE: In a recent version, brew update migrated all of my packages under /usr/local/Homebrew and then let me know that I can revert my permissions, not holding sudo access over /usr/local/:

sudo chown root:wheel /usr/local

Installing the latest Java JDK

Most certainly your OS X comes with an outdated Java version or no Java at all. In any case, you sure need to install the latest one.

Where is JAVA_HOME?

If you don't see the JAVA_HOME environment variable, don't worry. You can easily set it, without having to know the exact path to your JDKs location. Add the following to your ~/.bash_profile file:

export JAVA_HOME="$(/usr/libexec/java_home -v <JAVA_VERSION>)"

Where JAVA_VERSION will most probably be 1.8, but could also be set to 1.7 or 1.6 (depending on which version you installed)

Setting up your SSH keys

SSH keys allow you to communicate with other machines or services, using an encrypted connection, and without having to type a password every time. Setting up an SSH key is highly recommended, if not even required by most services, used by developers: GitHub, Heroku, BitBucket, etc.

To generate a new SSH key, open a Terminal and type:

ssh-keygen -t rsa

and follow the instructions. By default, ssh-keygen will generate a private key id_rsa and a public one id_rsa.pub and put them in the ~/.ssh directory. You can, of course, decide to choose a different path and location for your key files. Keep in mind that if you do so, you would have to either explicitly tell applications where to look for your keys, or add configuration entires in your ~/.ssh/config file. Both ways will be explained in further sections.

Share your public key

One of the common uses of SSH keys is to connect to other machines, without having to supply a password. To be able to do so, you have to share your newly generated public key with the remote machine. Open a terminal and type:

cat ~/.ssh/id_rsa.pub | ssh <REMOTE_MACHINE_ADDRESS> "cat >> ~/.ssh/authorized_keys"

The above command will require your password once, then it will append your public key over to the ~/.ssh/authorized_keys file on the remote machine. The next time you log in to the remote machien via ssh, your password will no longer be required.

Fixing your Git settings

Whether Git comes preinstalled on your OS X, or you set it up separately, make sure to have a look at the default settigns that it comes with. There are a couple of important setting that you might need to set up yourselves. For instance, your name and email. If you commit to a collaborative Git repository, your email and name are used to identify your commits, and distinguish them from those of your peers. Therefore, make sure to check the following two settings:

git config --get user.name
git config --get user.email

and change them to appropriate values, if needed:

git config --global user.name "John Doe"
git config --global user.email johndoe@example.com

Set your core Git editor to the one you're most comfortable with

Another setting you would want to have a look at, is your core Git editor. The default is set to vim. If you are like me, and you still haven't managed to really master those vim skills, you should look forward to changing it with something more lightweight, like nano, for instance:

git config --global core.editor <YOUR_FAVORITE_EDITOR_EG_NANO_OR_EMACS>

A text editor is used all over the place by Git, so, better make sure to check that out.

Other Developer Utilities

Ruby

RVM allows you to install and manage multiple Ruby environments on the same machine. This is really helpful, since often gems require a version of Ruby, different from the one that OSX gets shipped with.

Installing RVM

First and foremost, it is good to have Brew installed. You can use brew to install gpg - a security program used to check the security of the rvm download.

brew install gpg

Install the security key for rvm

command curl -sSL https://rvm.io/mpapis.asc | gpg --import -

And finally, rvm itself

curl -L https://get.rvm.io | bash -s stable

PHP

Composer

Composer is a dependency manager for PHP. It does the heaavy-duty job of automatically downloading dependency PHP libraries and organizing them in such a way that projects can use them right away. Composer is similar to Node.js' npm, Ruby's gem or Java's Ivy/Maven/Gradle (though Gradle and Maven are full-scale build systems. Downloading dependencies is just of the many things they're used for).

Installing Composer

Composer can be installed at a project level, or globally (at the user level). Installing Composer locally:

$ curl -sS https://getcomposer.org/installer | php
# now, you can run Composer using php
$ php composer.phar

or globally (which is basically, moving composer.phar under //usr/local/bin/):

$ curl -sS https://getcomposer.org/installer | php
$ mv composer.phar /usr/local/bin/composer
$ composer

OSX Apps

SublimeText

Add a Symbolic Link to the SublimeText Executable

Makes it easier to open your favorite code editor from the command line, without having to open Finder first.

ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl

to be continued ...

@NetOpWibby
Copy link

Oh wow, this looks good! I started my own a few months ago, but yours is pretty comprehensive.

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