Here is an early coder resource focusing on Ruby, JavaScript and Rails development. As dead tree media tends to obsolescence, latest online editions should be sought out if possible.
As a segue from the previous post on setting up the developer environment, I wanted to record my current setup for Sublime Text build 3083. This is not a post that debates the relative merits of this or that text editor. Maybe some other time.
I love Sublime Text. As a tool that I use daily in my chosen profession, I am more than happy to pay for the registered version and support the developers who make it. This should not be taken as a jab at any other text editors, open source or otherwise. Software developers and engineers are known to be obsessively defensive of their chosen favorite tools, most notably text editors.
Now that we have that out of the way, here is what works for me.
I use two machines, a desktop and laptop, so I sync Sublime Text settings via Dropbox. Instructions to do this are located here.
User Preferences
Here are the contents of the synced preferences file:
User/Preferences.sublime-settings
The usual suspects are here. I am a big fan of matching popular style-guides so I will use “tab size: 2”, and “translate tabs to spaces” enabled. “Save on focus lost” is a life saver as well as a time and sanity saver, especially on large projects.
“Trim trailing white space on save” is pretty self-explanatory, but for more information as to why “newline added on EOF (end of file)” should be used, check out this enlightening post on thoughtbot’s blog that explains the history.
Font
I use Inconsolata-dz, a variation of the superb Inconsolata font that includes straight quotes. I really love it, and can’t recommend it enough. Since I sync my Sublime settings from desktop to laptop and I like to reduce eye fatigue instead of squinting, it is set to a slightly larger font size than normal.
The original Inconsolata font created by Raph Levien is located here.
The Inconsolata-dz variant by David Zhou is available here.
Again, the subject of code fonts is highly contentious among the developer community, so in the interest of brevity I won’t elaborate further here. Maybe another day.
Theme
I use Jamie Wilson’s excellent theme, Predawn, and I follow the recommendations on that page for Markdown editing.
Since I recently reinstalled my OS, I may will definitely find more to download. One that springs to mind is SublimeLinter and its language-specific packages.
Key Bindings
Here is the contents of the synced Key bindings file:
User/Default (OSX).sublime-keymap
The ERB shortcut is used by SublimeERB to cycle between <%= %>, <% %>, <%- -%>, <%= -%>, <%# %>, and <% -%> and places the cursor helpfully inside of these monstrosities to ease the pain of typing embedded Ruby delimiters.
Paste and Indent makes this behavior default for ⌘-v, and allows me the option of reverting to the old paste using shift, in case I ever need it for some wacky reason.
Reindent saves me from hunting for this useful command in the menus.
Bric-a-Brac
I turn off the Minimap as it takes up valuable real estate and usually I just don’t use it.
What else? Oh yes, the app icon! The default icon that Sublime Text uses is a tad, well… it’s not nice to look at on the dock all the time. I prefer replacing it with a different one. This of course is just a cosmetic change, but there you have it. I regret nothing.
I use this one by Daniel Matarazzo adapted from an icon by Lindsay Mindler:
To get it, follow the instructions on Daniel’s GitHub repo, although I recommend renaming the Resources folder to Resources-old or something so you can get the originals back if you need them later.
A little extra step that I found was necessary after following the above instructions was to actually replace the icon in Finder:
First download your chosen image file, preferably a PNG for scalability. Select Sublime Text.app and type ⌘-i or right-click (a useful holdover from my PC days) and select Get Info. Drag and drop your chosen image file onto the ugly icon image in the Info window (top left corner). Enjoy your sleeker Sublime Text icon.
If you have any suggestions for packages, themes or key-bindings, or if there is something horribly wrong with the above information, please feel free to reach out to me via Twitter or shoot me an email.
I recently reinstalled Mac OS X from scratch and had to reconfigure all the little tweaks that had made my development workflow easier. These were settings that I had not noticed previously since they were so ubiquitous. Now that they were gone I felt naked and powerless on my clean install.
Setting out to reconfigure my settings, it was immediately noticeable that there were quite a few special details I had forgotten about, therefore I am posting this mostly as a ‘note to self’. If anyone stumbles upon this information, then I hope they gain some inspiration to customize their development environment as they see fit. Please keep in mind these are my own preferences and your mileage may vary.
Credit goes out to Mike Busch for giving the instructions upon which most of the steps below are based. Thanks Mike!
Mike’s Environment Linter “helps identify issues with OS X machine setup for basic web development with Ruby.” After running through the steps, go ahead and check the results with it, (for example my laptop for some strange reason had both rbenv and rvm, which is not recommended. I stuck with rbenv.)
Basics
Mac with OS X Mavericks or later, (I am on OS X Yosemite 10.10.)
Sublime Text 3
Dropbox (to sync text editor settings between multiple machines.)
Terminal - Later on we can get fancier with our Terminal program, but for now the default OS X Terminal will work just fine.
Google Chrome with Web Developer extension. I could make an entire post just about browser extensions, but this one is most relevant to my developer toolbox.
Again, these are the just the tools I like to use, so be sure and use your own preferred browser or text editor.
Setup
Install Command Line Tools
From Terminal:
Configure Sublime Text from the command line, subl.
According to the docs, this command is configured to run from ~/bin directory on your home user directory, which is a bit messy for various reasons. The following alternate instructions were gleaned from this gist.
In summary, from Terminal type: echo $PATH to check if /usr/local/bin directory appears. Due to the “clean install” of OS X, either it is not in the $PATH or the folder does not actually exist. This means we have to create it first if we wish to follow the instructions from the above gist. This has occurred to me on both Yosemite and El Capitan clean installs.
If the folder does not exist, type mkdir -p /usr/local/bin from your user root directory using sudo if privilege is required. I ran into some trouble with this by accidentally entering Sublime Text 2 command and somehow creating a bin file instead of folder in /usr/local. As always with sudo and rm, it is definitely a task to do slowly and mindfully. In my case I had to explicitly cd into /usr/local to create the /bin directory using sudo, after rm the erroneous bin file. Others have reported deleting the symlink and recreating it fixed errors on this. Your Mileage May Vary.
Here is how to find the subl command location, symlink and check it(note these are for Sublime Text 3.):
The preceding gives the path to subl. Use it in the next command.
Test in the Terminal subl -h. It should pop up some basic helpful commands. If so, you will now be able to open files and project folders in Sublime Text.
Finally, I modified my $PATH variable to prioritize /usr/local/bin:
(I used the vim-like built-in bash text editor nano to be cool.)
(The following is a great command to alias):
Yields:
So now my /usr/local/bin is first in line along the $PATH environmental variable. Later on as dotfiles start piling on, there may be more changes but for now, this is good enough to start.
Bash profile and UNIX environment
Coming from a Linux background, configuring one’s environment should be a familiar task. Luckily there is an huge source of information online if we are not sure where to begin.
Topher Lubaway has a neat group of UNIX/bash environment setup files, (also known as dotfiles,) located here. It includes some nice prompt coloring for git branch changes along with other nifty details, and I am partial to them since using them extensively. Thanks Topher!
Dotfiles are a source of pride for many developers and they are shared extensively. Check out dotfiles.github.io for more examples and tutorials. It is a tremendously helpful resource.
Follow all the instructions from Topher’s dotfiles repo including setting GitHub username and password, or just edit ~/.bash_profile and ~/.bashrc as you see fit. When choosing to use Topher’s dotfiles be aware Ruby gem awesome_print will be required when you open IRB sessions, but we can deal with that later.
Something that I like to change from Topher’s dotfiles are the Sublime Text key-bindings and preferences, but this could be a whole other future post so we won’t go into it at this time.
While we’re are at it, might as well add any alias commands we want and fancy ASCII art greetings when firing up a Terminal session. Get silly.
Run source ~/.bash_profile or exit and relaunch Terminal to confirm changes.
Homebrew
Since we have a clean install, we will need to install Homebrew. Run this command in the newly configured Terminal:
Staying true to the craft means we need to keep our tools in tip-top shape. Update Homebrew:
And make sure it is happy:
Fix any error messages until “Your system is ready to brew.” appears.
Make sure that our system is using Homebrew’s installed packages.
Run this command to output our $PATH variable in a more legible format:
And check that /usr/local/bin comes before both /usr/bin and /bin.
If we used the above dotfiles, it should. If not, open ~/.bash_profile and add: export PATH="/usr/local/bin:$PATH"
Install sqlite3 with Homebrew
Force OS X to use this version of sqlite3 and not the one that comes pre-installed:
Install postgres with Homebrew
Since postgres requires a server with which to interface, we use OS X’s launchd utility to keep this server running. Execute these two commands:
If all goes well, run which postgres to confirm the location is /usr/local/bin/postgres.
We can also check that postgres server is running by entering this ps or process status command:
Finally, create a default database and test our postgres client, psql.
This last command opens the sql console for the default database.
Install a Ruby Manager with Homebrew
I prefer to use rbenv. There are other options, notably rvm. Choose one and stick to it.
If we used rbenv and Topher’s dotfiles from earlier, go ahead and comment or delete out the lines of code that use rvm in ~/.bash_profile, ~/.bashrc and ~/.profile if they appear.
Install Ruby using a Ruby Manager
This will list all of the Rubies ruby-build can install. Choose one, likely the latest non-development build. For example:
And finally set the global/shell/local ruby:
Run:
To make sure we are not using the system’s pre-installed Ruby. It should say something like this: /Users/Nyc/.rbenv/shims/ruby
Restart the Terminal.
Install git with Homebrew
Make sure we’re using git from Homebrew:
Should give: /usr/local/bin/git
If we didn’t earlier, then set username, email for git.
Finally, set up Sublime Text as default editor for git:
Install node with Homebrew
Install Ruby gems
Make sure the load path is right.
Should yield, /Users/Nyc/.rbenv/shims/gem or similar.
Last but not least, let’s update our most likely woefully out of date default installation of bash. See the current version running with:
To install:
We need to add this version to /etc/shells.
And change the shell command:
Quit Terminal completely, and restart a new Terminal session. Confirm the version has been updated.
Conclusion
After this initial setup, I like to customize the text editor and use an alternate Terminal program like iTerm, OS X settings and whatnot, but I think I might save that for another post.
Something that I learned while posting this is that creating your own personal dotfiles absolutely simplifies the process of getting a development environment up and running quickly - especially if you have many workstations!
Feel free to reach out to me on Twitter or email if I missed anything. Feedback is always welcome.