Until now I have used the mac os for 3 years, but I never learn about the relative development things of Mac os. In this articles, I will take introduction about some tools for the developer on Mac. The main contents are from the macOS setup Guide from Sourabh. It is very suitable for the rookie like me.
Table of Contents
XCode
Xcode is an development environment of Apple os system, like Visual Stdio of Microsoft. The whole thing could be downloaded and installed from App Store or offical site of Apple. And Xcode command line tools could be installed by command:
1
|
|
It is a package of shell command tools for Mac OS development, many things is dependent on it.
Homebrew
Homebrew is a package manager for macOS which help developer install and uninstall many important development tools.
To install Homebrew by running command:
1
|
|
Usage
To install a package:
1
|
|
To update packages:
1
|
|
To see the package list need to be updated
1
|
|
To update a package:
1
|
|
To remove packages of old version:
1
|
|
To see the installed package list with version number:
1
|
|
ITerm2
iTerm2 is a great replacement for Apple’s Terminal. It is highly customizable and includes many useful features.
There are 2 ways to Install iTerm2. First, The official website offer the installer. And we also could install it by Homebrew.
1
|
|
Customization
We can define color, font, size, hotkeys for the iTerm2, and also there are many 3rd party resources from internet.
Zsh
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(Wiki). There are a lot of articles to compare Zsh with Bash (Apple’s original shell). e.g. Bash vs Zsh: A comparison of two command line shells by Nicholas Morera.
To install Zsh and zsh-completions by Homebrew:
1
|
|
Then, we can customize the zsh by the framework Oh My Zsh, to install it by curl command.
1
|
|
If you’re still in the default shell, change default shell to zsh manually:
1
|
|
Configure plugins and theme of zsh by editing ~/.zshrc file. (refer the wiki)
1 2 3 4 5 6 7 8 9 10 |
|
Finally, we can create a setting file such as env.sh
to make some pre-defined settings, And add it to .zshrc
with source <envpath>/env.sh
. One config template (Ref) is like:
#!/bin/zsh
# PATH
export PATH="/usr/local/share/python:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
export EDITOR='subl -w'
# export PYTHONPATH=$PYTHONPATH
# export MANPATH="/usr/local/man:$MANPATH"
# Virtual Environment
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/projects
source /usr/local/bin/virtualenvwrapper.sh
# Owner
export USER_NAME="YOUR NAME"
eval "$(rbenv init -)"
# FileSearch
function f() { find . -iname "*$1*" ${@:2} }
function r() { grep "$1" ${@:2} -R . }
#mkdir and cd
function mkcd() { mkdir -p "$@" && cd "$_"; }
#Aliases
alias cppcompile='c++ -std=c++11 -stdlib=libc++'
# Use sublimetext for editing config files
alias zshconfig="subl ~/.zshrc"
alias envconfig="subl ~/projects/config/env.sh"
Git
Git is most important version management tools for any developer. It is hard to image anyone do works without it.
To install it by Homebrew:
1
|
|
Then define the user of Github:
1 2 |
|
And config the SSH connection is nessceary for us, following the steps from here to generate the ssh key and upload it to Github.
For the ignore some file out of mangement by git, we shall create the file ~/.gitignore
to setting the files (e.g. .DS_Store
) not be tracked. One template could be found here.
For configring the diff and merge tool (e.g. Beyond Compare) by commands:
1 2 3 4 5 |
|
ATOM
There are huge amounts of editors or IDE in MACOS, e.g. VIM, Sublime, JetBrains and so on. In this article, I will introduction ATOM Editor. We can download the install fom macOS, linux and windows from its official site.
It is a highly customizable editor based on Electron, a framework that enables cross-platform desktop applications using Chromium and Node.js(ref)). A lot of resources about themes and plugings could be used to support what language you develop.
And we can create a symlink of atom if it exists for using it from command line directly. Then we can use atom file
and atom folder
to open relatived file and folder.
1
|
|
Python
From this part, we will introduce some program languages setting-up on MacOS including python, c++, Java, Scala, Ruby, Nodejs, Go and Latex.
macOS already includes python, but we do not mess with the system Python, so we need install our own versions. The first way is that you can install Python by Homebrew.
1
|
|
Another way is to use pyenv which could help you to manage multiple versions of Python (e.g. 2.x and 3.x). It works like rbenv for Ruby. First, we must install pyenv by Homebrew.
1
|
|
After installing, we should add ‘pyenv init’ to the shell to enable shims and autocompletion.
1
|
|
Restart shell to reload the settings, then we can start to use pyenv.
1
|
|
The important commands are listed following with comments:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Tools
pip is important for developer to install and manage python packages:
1 2 3 4 |
|
Virtualenv is a tool which create an isolated Python enviroment for each of your projects.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
Numpy, Scipy and Matplotlib are scientific liberary for Python. They could installed through pip or Homebrew, see here.
CPlusPlus
XCode contains c++, and we could also install c++ by Homebrew.
1
|
|
And we can add alias to shell env for compiling files from terminal.
1
|
|
Then we could run cpp file directly using cppcompile main.cpp
.
Java
Go to Oracle website to download the macOS version of Java and install. Then we could run java -version
to check whether it is installed correctly.
And after installing, we should add Java path to env file.
1
|
|
Finally, choose an IDE to start your develop, e.g. Eclipse.
Ruby
Ruby is similar as Python in MacOS. We could install it directly by Homebrew. And we also could use rbenv
to install and manage multiple versions of Ruby like pyenv
.
1 2 3 4 5 6 7 8 9 |
|
RubyGems is Ruby package management tool, it should be installed with Ruby. Check by which gem
. Usage is shown as below.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Node.js
Nodejs is an open-source, cross-platform JavaScript run-time environment for executing JavaScript code server-side(wiki). Like Python and Ruby, it also has an version management tool - nvm. We can use it to install and manage versions of Nodejs. Usage shows below.
1 2 3 4 5 6 7 8 9 10 |
|
And nodejs also has its package management tool npm
, The usage is like pip
for Python and gem
for Ruby.
1 2 3 4 5 6 |
|
Go
Go—‘golang’ is a programming language created by Google.
We could install it by Homebrew.
1
|
|
Then config the enviroment by inserting path to env.sh
1 2 3 4 |
|
How to write a simple “Hello World” program, please refer here.
To import and use package, we will use command go get
.
1
|
|
Package using example:
package main
import (
"net/http"
"log"
"github.com/gorilla/mux" // Your imported package
)
func YourHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Gorilla!\n"))
}
func main() {
r := mux.NewRouter()
// Routes consist of a path and a handler function.
r.HandleFunc("/", YourHandler)
// Bind to a port and pass our router in
log.Fatal(http.ListenAndServe(":8000", r))
}
Latex
LaTex, which is pronounced “Lah-tech” or “Lay-tech”, is a document preparation system for high-quality typesetting. It is not a word processors like Microsoft Word or Apple Pages. It is like a markup language to using kinds of tags or commands to generate a structure of documents.
To install LaTex on MacOS, we could download MacTex installer. It includes additional programs such as an editor and a BibTeX reference manager that help users to work with TeX outside of the command line. But it is big(2G).
Another way is to install BasicTex, only 100M size, but we will be faced with the tasks of installing additional programs and installing missing packages.
Others
About other development tools, for me, I use Beyond Compare, Matlab, Android Studio, VisualBox, Blender and Octopress with Heroku for the blog post.
Reference
“MacOS setup guide” http://sourabhbajaj.com/mac-setup/ Sourabh Bajaj