avarx version - thanks to nicolahery
This document describes how I set up my developer environment on a new MacBook or iMac.
- System update
- System preferences
- Google Chrome
- iTerm2
- Homebrew
- zsh
- Consolas
- Beautiful terminal
- Git
- Sublime Text
- PEAR
- CodeSniffer
- Python
- Node.js
- JSHint
- Ruby and RVM
- Metasploit
- JTR Jumbo
- Hashcat
- LESS
- Projects folder
- Apps
First thing you need to do, on any OS actually, is update the system! For that: Apple Icon > Software Update...
If this is a new computer, there are a couple tweaks I like to make to the System Preferences. Feel free to follow these, or to ignore them, depending on your personal preferences.
In Apple Icon > System Preferences:
- Trackpad > Tap to click
- Keyboard > Key Repeat > Fast (all the way to the right)
- Keyboard > Delay Until Repeat > Short (all the way to the right)
- Dock > Automatically hide and show the Dock
Hide desktop:
defaults write com.apple.finder CreateDesktop -bool false
Show hidden files:
defaults write com.apple.finder AppleShowAllFiles TRUE
Install your favorite browser, mine happens to be Chrome.
Download from www.google.com/chrome. Open the .dmg file once it's done downloading (this will mount the disk image), and drag and drop the Google Chrome app into the Applications folder (on the Mac, most applications are installed this way). When done, you can unmount the disk in Finder (the small "eject" icon next to the disk under Devices).
Since we're going to be spending a lot of time in the command-line, let's install a better terminal than the default one. Download and install iTerm2 (the newest version, even if it says "beta release").
In Finder, drag and drop the iTerm Application file into the Applications folder.
You can now launch iTerm, through the Launchpad for instance.
Let's just quickly change some preferences. In iTerm > Preferences..., under the tab General, uncheck Confirm closing multiple sessions and Confirm "Quit iTerm2 (Cmd+Q)" command under the section Closing.
In the tab Profiles, create a new one with the "+" icon, and rename it to your first name for example. Then, select Other Actions... > Set as Default. Finally, under the section Window, change the size to something better, like Columns: 125 and Rows: 35.
When done, hit the red "X" in the upper left (saving is automatic in OS X preference panes). Close the window and open a new one to see the size change.
Package managers make it so much easier to install and update applications (for Operating Systems) or libraries (for programming languages). The most popular one for OS X is Homebrew.
An important dependency before Homebrew can work is the Command Line Tools for Xcode. These include compilers that will allow you to build things from source.
Now, Xcode weights something like 2GB, and you don't need it unless you're developing iPhone or Mac apps. Good news is Apple provides a way to install only the Command Line Tools, without Xcode. To do this you need to go to http://developer.apple.com/downloads, and sign in with your Apple ID (the same one you use for iTunes and app purchases). Unfortunately, you're greeted by a rather annoying questionnaire. All questions are required, so feel free to answer at random.
Once you reach the downloads page, search for "command line tools", and download the latest Command Line Tools (OS X Mountain Lion) for Xcode. Open the .dmg file once it's done downloading, and double-click on the .mpkg installer to launch the installation. When it's done, you can unmount the disk in Finder.
Note: If you are running OS X 10.9 Mavericks, then you can install the Xcode Command Line Tools directly from the command line with $ xcode-select --install
, and you don't have to go through the download page and the questionnaire.
Finally, we can install Hombrew! In the terminal paste the following line (without the $
), hit Enter, and follow the steps on the screen:
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
One thing we need to do is tell the system to use programs installed by Hombrew (in /usr/local/bin
) rather than the OS default if it exists. We do this by adding /usr/local/bin
to your $PATH
environment variable:
$ echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile
Open a new terminal tab with Cmd+T (you should also close the old one), then run the following command to make sure everything works:
$ brew doctor
To install a package (or Formula in Homebrew vocabulary) simply type:
$ brew install <formula>
To update Homebrew's directory of formulae, run:
$ brew update
Note: I've seen that command fail sometimes because of a bug. If that ever happens, run the following (when you have Git installed):
$ cd /usr/local
$ git fetch origin
$ git reset --hard origin/master
To see if any of your packages need to be updated:
$ brew outdated
To update a package:
$ brew upgrade <formula>
Homebrew keeps older versions of packages installed, in case you want to roll back. That rarely is necessary, so you can do some cleanup to get rid of those old versions:
$ brew cleanup
To see what you have installed (with their version numbers):
$ brew list --versions
The Z shell (zsh) is a Unix shell that can be used as an interactive login shell and as a powerful command interpreter for shell scripting.
brew install zsh
I really like the Consolas font for coding. Being a Microsoft (!) font, it is not installed by default. Since we're going to be looking at a lot of terminal output and code, let's install it now.
There are two ways we can install it. If you bought Microsoft Office for Mac, install that and Consolas will be installed as well.
If you don't have Office, follow these steps:
$ brew install cabextract
$ cd ~/Downloads
$ mkdir consolas
$ cd consolas
$ curl -O http://download.microsoft.com/download/f/5/a/f5a3df76-d856-4a61-a6bd-722f52a5be26/PowerPointViewer.exe
$ cabextract PowerPointViewer.exe
$ cabextract ppviewer.cab
$ open CONSOLA*.TTF
And click Install Font. Thanks to Alexander Zhuravlev for his post.
Since we spend so much time in the terminal, we should try to make it a more pleasant and colorful place. What follows might seem like a lot of work, but trust me, it'll make the development experience so much better.
Let's go ahead and start by changing the font. In iTerm > Preferences..., under the tab Profiles, section Text, change both fonts to Consolas 13pt.
Now let's add some color. I'm a big fan of the Solarized color scheme. It is supposed to be scientifically optimal for the eyes. I just find it pretty.
Scroll down the page and download the latest version. Unzip the archive. In it you will find the iterm2-colors-solarized
folder with a README.md
file, but I will just walk you through it here:
- In iTerm2 Preferences, under Profiles and Colors, go to Load Presets... > Import..., find and open the two .itermcolors files we downloaded.
- Go back to Load Presets... and select Solarized Dark to activate it. Voila!
Note: You don't have to do this, but there is one color in the Solarized Dark preset I don't agree with, which is Bright Black. You'll notice it's too close to Black. So I change it to be the same as Bright Yellow, i.e. R 83 G 104 B 112.
Not a lot of colors yet. We need to tweak a little bit our Unix user's profile for that. This is done (on OS X and Linux), in the ~/.bash_profile
text file (~
stands for the user's home directory).
We'll come back to the details of that later, but for now, just download the files .bash_profile, .bash_prompt, .aliases attached to this document into your home directory (.bash_profile
is the one that gets loaded, I've set it up to call the others):
$ cd ~
$ curl -O https://raw.githubusercontent.com/avarx/mac-dev-setup/master/.bash_profile
$ curl -O https://raw.githubusercontent.com/avarx/mac-dev-setup/master/.bash_prompt
$ curl -O https://raw.githubusercontent.com/avarx/mac-dev-setup/master/.aliases
With that, open a new terminal tab (Cmd+T) and see the change! Try the list commands: ls
, ls -lh
(aliased to ll
), ls -lha
(aliased to la
).
At this point you can also change your computer's name, which shows up in this terminal prompt. If you want to do so, go to System Preferences > Sharing.
Now we have a terminal we can work with!
(Thanks to Mathias Bynens for his awesome dotfiles.)
What's a developer without Git? To install, simply run:
$ brew install git
When done, to test that it installed fine you can run:
$ git --version
And $ which git
should output /usr/local/bin/git
.
Let's set up some basic configuration. Download the .gitconfig file to your home directory:
$ cd ~
$ curl -O https://raw.githubusercontent.com/avarx/mac-dev-setup/master/.gitconfig
It will add some color to the status
, branch
, and diff
Git commands, as well as a couple aliases. Feel free to take a look at the contents of the file, and add to it to your liking.
Next, we'll define your Git user (should be the same name and email you use for GitHub and Heroku):
$ git config --global user.name "Your Name Here"
$ git config --global user.email "[email protected]"
They will get added to your .gitconfig
file.
To push code to your GitHub repositories, we're going to use the recommended HTTPS method (versus SSH). So you don't have to type your username and password everytime, let's enable Git password caching as described here:
$ git config --global credential.helper osxkeychain
Note: On a Mac, it is important to remember to add .DS_Store
(a hidden OS X system file that's put in folders) to your .gitignore
files. You can take a look at this repository's .gitignore file for inspiration.
With the terminal, the text editor is a developer's most important tool. Everyone has their preferences, but unless you're a hardcore Vim user, a lot of people are going to tell you that Sublime Text is currently the best one out there.
Go ahead and download it. Open the .dmg file, drag-and-drop in the Applications folder, you know the drill now. Launch the application.
Note: At this point I'm going to create a shortcut on the OS X Dock for both for Sublime Text and iTerm. To do so, right-click on the running application and select Options > Keep in Dock.
Sublime Text is not free, but I think it has an unlimited "evaluation period". Anyhow, we're going to be using it so much that even the seemingly expensive $70 price tag is worth every penny. If you can afford it, I suggest you support this awesome tool. :)
Just like the terminal, let's configure our editor a little. Go to Sublime Text 3 > Preferences > Settings - User and paste the following in the file that just opened:
{
"draw_white_space": "all",
"font_size": 12,
"ignored_packages":
[
"Vintage",
"RestructuredText"
],
"show_encoding": true,
"tab_size": 4,
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true,
"word_wrap": "true"
}
Feel free to tweak these to your preference. When done, save the file and close it.
Now for the color. I'm going to change two things: the Theme (which is how the tabs, the file explorer on the left, etc. look) and the Color Scheme (the colors of the code). Again, feel free to pick different ones, or stick with the default.
http://equinusocio.github.io/material-theme/ A popular Theme is the Material Theme. To install it, run:
https://packagecontrol.io/packages/Material%20Theme
Sublime Text 3 already supports syntax highlighting for a lot of languages. I'm going to install a couple that are missing:
$ cd ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/
$ git clone -b SublimeText2 https://github.com/kuroir/SCSS.tmbundle.git SCSS
Let's create a shortcut so we can launch Sublime Text from the command-line:
$ cd ~
$ mkdir bin
$ ln -s "/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl" ~/bin/subl
Now I can open a file with $ subl myfile.py
or start a new project in the current directory with $ subl .
. Pretty cool.
Sublime Text is very extensible. For now we'll leave it like that, we already have a solid installation. To add more in the future, a good place to start would be to install the Sublime Package Control.
Packages I installed:
"installed_packages":
[
"AdvancedNewFile",
"Case Conversion",
"ColorPicker",
"DocBlockr",
"Emmet",
"Indent XML",
"jQuery",
"LESS",
"Markdown Preview",
"Package Control",
"php-snippets",
"Restructured Text (RST) Snippets",
"RestructuredText Improved",
"Sass",
"SideBarEnhancements",
"StringUtilities",
"SublimeCodeIntel",
"Sublimerge Pro",
"Terminal",
"TYPO3 Fluid Snippets",
"TypoScript",
"WordPress"
]
http://blog.avarx.io/pear/
http://blog.avarx.io/codesniffer/
OS X, like Linux, ships with Python already installed. But you don't want to mess with the system Python (some system tools rely on it, etc.), so we'll install our own version with Homebrew. It will also allow us to get the very latest version of Python 2.7.
The following command will install Python 2.7 and any dependencies required (it can take a few minutes to build everything):
$ brew install python
When finished, you should get a summary in the terminal. Running $ which python
should output /usr/local/bin/python
.
It also installed Pip (and its dependency Distribute), which is the package manager for Python. Let's upgrade them both:
$ pip install --upgrade distribute
$ pip install --upgrade pip
Executable scripts from Python packages you install will be put in /usr/local/share/python
, so let's add it to the $PATH
. To do so, we'll create a .path
text file in the home directory (I've already set up .bash_profile
to call this file):
$ cd ~
$ subl .path
And add these lines to .path
:
PATH=/usr/local/share/python:$PATH
export PATH
Save the file and open a new terminal to take the new $PATH
into account (everytime you open a terminal, .bash_profile
gets loaded).
Here are a couple Pip commands to get you started. To install a Python package:
$ pip install <package>
To upgrade a package:
$ pip install --upgrade <package>
To see what's installed:
$ pip freeze
To uninstall a package:
$ pip uninstall <package>
Install Node.js with Homebrew:
$ brew update
$ brew install node
The formula also installs the npm package manager. However, as suggested by the Homebrew output, we need to add /usr/local/share/npm/bin
to our path so that npm-installed modules with executables will have them picked up.
To do so, add this line to your ~/.path
file, before the export PATH
line:
PATH=/usr/local/share/npm/bin:$PATH
Open a new terminal for the $PATH
changes to take effect.
We also need to tell npm where to find the Xcode Command Line Tools, by running:
$ sudo xcode-select -switch /usr/bin
(If Xcode Command Line Tools were installed by Xcode, try instead:)
$ sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
Node modules are installed locally in the node_modules
folder of each project by default, but there are at least two that are worth installing globally. Those are CoffeeScript and Grunt:
$ npm install -g coffee-script
$ npm install -g grunt-cli
To install a package:
$ npm install <package> # Install locally
$ npm install -g <package> # Install globally
To install a package and save it in your project's package.json
file:
$ npm install <package> --save
To see what's installed:
$ npm list # Local
$ npm list -g # Global
To find outdated packages (locally or globally):
$ npm outdated [-g]
To upgrade all or a particular package:
$ npm update [<package>]
To uninstall a package:
$ npm uninstall <package>
##JSHint
JSHint is a JavaScript developer's best friend.
If the extra credit assignment to install Sublime Package Manager was completed, JSHint can be run as part of Sublime Text.
Install JSHint via npm (global install preferred)
$ npm install -g jshint
Follow additional instructions on the JSHint Package Manager page or build it manually.
Like Python, Ruby is already installed on Unix systems. But we don't want to mess around with that installation. More importantly, we want to be able to use the latest version of Ruby.
When installing Ruby, best practice is to use RVM (Ruby Version Manager) which allows you to manage multiple versions of Ruby on the same machine. Installing RVM, as well as the latest version of Ruby, is very easy. Just run:
$ curl -L https://get.rvm.io | bash -s stable --ruby
When it is done, both RVM and a fresh version of Ruby 2.0 are installed. The following line was also automatically added to your .bash_profile
:
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
I prefer to move that line to the .extra
file, keeping my .bash_profile
clean. I suggest you do the same.
After that, start a new terminal and run:
$ type rvm | head -1
You should get the output rvm is a function
.
The following command will show you which versions of Ruby you have installed:
$ rvm list
The one that was just installed, Ruby 2.0, should be set as default. When managing multiple versions, you switch between them with:
$ rvm use system # Switch back to system install (1.8)
$ rvm use 2.0.0 --default # Switch to 2.0.0 and sets it as default
Run the following to make sure the version you want is being used (in our case, the just-installed Ruby 1.9.3):
$ which ruby
$ ruby --version
You can install another version with:
$ rvm install 1.9.3
To update RVM itself, use:
$ rvm get stable
RubyGems, the Ruby package manager, was also installed:
$ which gem
Update to its latest version with:
$ gem update --system
To install a "gem" (Ruby package), run:
$ gem install <gemname>
To install without generating the documentation for each gem (faster):
$ gem install <gemname> --no-document
To see what gems you have installed:
$ gem list
To check if any installed gems are outdated:
$ gem outdated
To update all gems or a particular gem:
$ gem update [<gemname>]
RubyGems keeps old versions of gems, so feel free to do come cleaning after updating:
$ gem cleanup
I mainly use Ruby for the CSS pre-processor Compass, which is built on top of Sass:
$ gem install compass --no-document
xcode-select --install
Java http://download.oracle.com/otn-pub/java/jdk/8u40-b27/jdk-8u40-macosx-x64.dmg
brew install nmap
brew install postgresql --without-ossp-uuid
mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/postgresql/9.4.1/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
createuser msf -P -h localhost
createdb -O msf msf -h localhost
gem install pg sqlite3 msgpack activerecord redcarpet rspec simplecov yard bundler
cd /usr/local/share/
git clone https://github.com/rapid7/metasploit-framework.git
cd metasploit-framework
for MSF in $(ls msf*); do ln -s /usr/local/share/metasploit-framework/$MSF /usr/local/bin/$MSF;done
sudo chmod go+w /etc/profile
sudo echo export MSF_DATABASE_CONFIG=/usr/local/share/metasploit-framework/config/database.yml >> /etc/profile
gems need to be installed
bundle install
vi /usr/local/share/metasploit-framework/config/database.yml
production:
adapter: postgresql
database: msf
username: msf
password: <password>
host: 127.0.0.1
port: 5432
pool: 75
timeout: 5
source /etc/profile
source ~/.bash_profile
Start
./msfconsole
Check DB
msf> db_status
wget http://www.openwall.com/john/j/john-1.8.0-jumbo-1.tar.gz
wget http://hashcat.net/files/hashcat-0.49.7z
CSS preprocessors are becoming quite popular, the most popular processors are LESS and SASS. Preprocessing is a lot like compiling code for CSS. It allows you to reuse CSS in many different ways. Let's start out with using LESS as a basic preprocessor, it's used by a lot of popular CSS frameworks like Bootstrap.
To install LESS you have to use NPM / Node, which you installed earlier using Homebrew. In the terminal use:
$ npm install less --global
Note: the --global
flag is optional but it prevents having to mess around with file paths. You can install without the flag, just know what you're doing.
You can check that it installed properly by using:
$ lessc --version
This should output some information about the compiler:
lessc 1.5.1 (LESS Compiler) [JavaScript]
Okay, LESS is installed and running. Great!
There's a lot of different ways to use LESS. Generally I use it to compile my stylesheet locally. You can do that by using this command in the terminal:
$ lessc template.less template.css
The two options are the "input" and "output" files for the compiler. The command looks in the current directory for the LESS stylesheet, compiles it, and outputs it to the second file in the same directory. You can add in paths to keep your project files organized:
$ lessc less/template.less css/template.css
Read more about LESS on their page here: http://lesscss.org/
This really depends on how you want to organize your files, but I like to put all my version-controlled projects in ~/Projects
. Other documents I may have, or things not yet under version control, I like to put in ~/Dropbox
(if you have Dropbox installed), or ~/Documents
.
Here is a quick list of some apps I use, and that you might find useful as well:
- Dropbox: File syncing to the cloud. I put all my documents in Dropbox. It syncs them to all my devices (laptop, mobile, tablet), and serves as a backup as well! (Free for 2GB)
- 1Password: Allows you to securely store your login and passwords. Even if you only use a few different passwords (they say you shouldn't!), this is really handy to keep track of all the accounts you sign up for! Also, they have a mobile app so you always have all your passwords with you (syncs with Dropbox). A little pricey though. There are free alternatives. ($50 for Mac app, $18 for iOS app)
- Evernote: If I don't write something down, I'll forget it. As a developer, you learn so many new things every day, and technology keeps changing, it would be insane to want to keep it all in your head. So take notes, sync them to the cloud, and have them on all your devices. To be honest, I switched to Simplenote because I only take text notes, and I got tired of Evernote putting extra spaces between paragraphs when I copy & pasted into other applications. Simplenote is so much better for text notes (and it supports Markdown!). (Both are free)
- Moom: Don't waste time resizing and moving your windows. Moom makes this very easy. ($10)
- Wireshark: Wireshark is the world's foremost network protocol analyzer. (free)
- Tunnelblick: VPN. (free)
- Slack: Be less busy. (free)