Skip to content

Instantly share code, notes, and snippets.

@nair-ayush
Last active January 6, 2021 19:56
Show Gist options
  • Save nair-ayush/40eea509f463a2a113634048029c009e to your computer and use it in GitHub Desktop.
Save nair-ayush/40eea509f463a2a113634048029c009e to your computer and use it in GitHub Desktop.
Mac Setup with Development Environment

This is a guide for setting up an Apple Mac for software development. Current versions of macOS have a fairly good default configuration for general-purpose use, but you do need to to adjust some of the security settings. In addition, you need to install several pieces of software in order to make the system useful for development.

DO This First!

Log in once, run Software Update, and ensure that the operating system is at the latest point release. After all of the updates have been applied, restart the computer.

Log in again and create an Admin user account for your use. If other people will be using the machine, create Standard accounts for them. Log out of the initial account, and log in to the Admin account that you have just created.

You should also find an external hard drive. Begin using Time Machine as soon as possible, as it provides the most easy method for backing up your system.

Configuring the Trackpad

To make the trackpad behave correctly, ensure that these settings are enabled:

  • System Preferences > Trackpad > Tap to click
  • System Preferences > Accessibility > Mouse & Trackpad > Trackpad Options… > Enable dragging
  • System Preferences > Trackpad > Scroll Direction : Natural

Basic Settings

Select System Preferences > Security & Privacy, and set the following:

  • Under General, set require a password after sleep or screen saver begins to immediately
  • Click Advanced… and select Require an administrator password to access system-wide preferences
  • Under Firewall, click Turn Firewall On.
  • Put System Preferences in the Dock.
  • Enable keyboard access for all controls
    • When filling out forms, tapping the Tab key allows you to cycle through text boxes and lists only by default. While this is helpful, drop-down boxes, radio buttons, and other forms of input are skipped entirely.

    • To change this behavior and allow for tabbing through all forms of input, go to System Preferences > Keyboard > Shortcuts. Select the radio button for All Controls under the Full Keyboard Access to enable this function

If you're going to use Alfred then uncheck Spotlight. Go to System Preferences > Keyboard > Shortcuts and then in the Spotlight tab uncheck Show Spotlight Search

Finder Settings

Below are some settings that may help your experience with Finder all the more useful:

  • Modify the View/Layout of the Finder. Go to View > Change Layout.
  • Enable Status Bar and Path Bar. View > Show Path Bar/ Status Bar.
  • Adjust Finder settings to list folders above files. Go to Finder > Preferences > Advanced > Keep Folders On Top When Sorting By Name
  • Go to General and check everything.

Keyboard Shortcuts

Action Shortcut
Force Quit an App ⌘ + Option + Esc
Quick Look Space
View Hidden Files ⌘ + Shift + .
Forward Delete Fn + Delete
Delete word by word Option + Delete
Scroll to Very Top/Bottom ⌘ + Up or Down
Scroll to Start/End of line ⌘ + Right/Left
Take a screenshot of the entire screen ⌘ + Shift + 3
Take a screenshot of an area of the screen ⌘ + Shift + 4

Enable File Vault[OPTIONAL]

Current versions of macOS include File Vault 2, a full-disk encryption system that has little in common with the much more limited File Vault 1. You should enable File Vault NOW, because it is the only protection against anyone with physical access to your computer. All other security measures will be completely bypassed if someone with physical access simply restarts the computer with a bootable pen drive.

File Vault really is secure, which means that you can permanently lose access to your data if you lose the passwords and the recovery key.

Setting Up Time Machine Backups

Time Machine is simple to set up. Just take a suitably large external hard drive, plug it in to your Mac, and agree when prompted. The drive setup process will reformat the hard drive. The only settings that may need to change are the exclusions.

Choose System Preferences > Time Machine, and click Options. Add to the exclusions list any folders that contain ISO disk images, virtual machines, or database files (such as Entourage). If the external hard drive is short of space, exclude the System folder.

Set app download tolerance level

If you want to download apps from the web at large and not just from the Mac App Store, you'll need to tell macOS to loosen up on the reins a bit. Go to System Preferences > Security & Privacy, click the General tab and then click lock in the lower-left corner and enter your password to make changes. Next, for Allow apps downloaded from choose App Store and identified developers.

Mute Siri

Siri doesn't have to speak her responses aloud—she can silently display them on screen. If you'd prefer this option, open System Preferences > Siri. Finally, next to the Voice Feedback heading, tick Off. From the same dialog box, you can tweak other aspects of Siri: Try changing the voice, and if you prefer a less cluttered interface, experiment with hiding the icon from the menu bar.

Setting up for Development

The first step is to install a compiler. The easiest way to install one is with the Xcode Command Line Tools package.

Once you have the compiler that is provided by Xcode, you can use Homebrew to install everything else that you need. Homebrew itself manages packages for command-line tools and services. The Cask extension to Homebrew enables you to install graphical desktop applications.

Get XCode

Apple now provide the Xcode suite as a free download from the App Store. To install Xcode Command Line Tools, install Xcode from the App Store, then open a Terminal window and enter the following command:

xcode-select --install

You can skip installing XCode from the App Store and directly execute the above command. A dialog box will open saying install complete XCode or just the XCode Command Line Tools. Choose whichever option you want.

Install Homebrew

Run the macSetup.sh in your $HOME folder for all the steps listed below to happen automatically after installing xcode. But make sure you input your own credentials in the script before running it.

Homebrew provides a package management system for macOS, enabling you to quickly install and update the tools and libraries that you need. Follow the instructions on the site.

You should also amend your PATH, so that the versions of tools that are installed with Homebrew take precedence over others. To do this, edit the file .bash_profile in your home directory to include this line:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
export PATH="/usr/local/bin:/usr/local/sbin:~/bin:$PATH" >> $HOME/.bash_profile

Then update brew to the latest version and then installing cask

brew update
brew tap caskroom/cask

Installing Git

The Xcode Command Line Tools include a copy of Git, which is now the standard for Open Source development, but this will be out of date.

To install a newer version of Git than Apple provide, use Homebrew. Enter this command in a terminal window:

brew install git

Always set your details before you create or clone repositories on a new system. This requires two commands in a terminal window:

git config --global user.name "Your Name"
git config --global user.email "you@your-domain.com"
git config --global color.ui auto
git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset%n' --abbrev-commit --date=relative --branches"
git config --global alias.blg "log --graph --pretty=oneline --abbrev-commit"

The last two are git aliases to view the commit/branch log history for git initialised repositories. Execute git lg to view the entire branch tree from master to all nodes in a tree fashion. Execute git blg to view the branch history and its nodes for the current branch that you are in(branch that you have checked out to).

If you think the terms lg and blg are not to your liking just change the names near the alias.* in the last 2 lines above for your chosen terms. Change it in the execute.sh file if you use that.

Creating SSH key

The simplest way to generate a key pair is to run ssh-keygen without arguments. In this case, it will prompt for the file in which to store keys.

First, the tool asked where to save the file. SSH keys for user authentication are usually stored in the user's $HOME/.ssh directory. Then it asks to enter a passphrase. The passphrase is used for encrypting the key, so that it cannot be used even if someone obtains the private key file. The algorithm is selected using the -t option and key size using the -b option. The following commands illustrate:

ssh-keygen -t rsa -b 4096
ssh-keygen -t dsa
ssh-keygen -t ecdsa -b 521
ssh-keygen -t ed25519

Your identification has been saved in $HOME/.ssh/id_rsa. Your public key has been saved in $HOMe/.ssh/id_rsa.pub. Copy the public key to copy to you GitHub account or wherever

Caching Git credenials with OSXKeychain

Run git config --global credential.helper osxkeychain to save your username and password so that you dont have to re-enter the credentials again whenever dealing with remotes.

Text Editor

To install Visual Studio Code, enter this command in a terminal window:

brew cask install visual-studio-code

Set the EDITOR environment variable to open VS Code as the default text editor[OPTIONAL].

export EDITOR="code -w" >> $HOME/.bash_profile

Cleanup the unneeded dependencies

brew cleanup

Pipenv for Python Development

Unfortunately, macOS includes a copy of Python 2, so you will need to install Python 3 yourself. To maintain current and clean Python environments, you should also install pipenv. It drives the pip and virtual environment features that are included with Python itself, but is more powerful and easier to use than working with these features directly.

Enter this command to install Python 3 and pipenv using Homebrew:

brew install python3 pipenv
python3 -V

R and RStudio for R Development

Installation of R and RStudio is easy with brew.

brew install r
brew cask install rstudio

Note: Run the rPackages.R to install the basic libraries for R developement.

Java Development

Visit here to download the .dmg file. Drag the installer icon to the Applications folder in the installer page.

You then need to set the $JAVA_HOME variable so that applications know where to look for the JDK. Use export $JAVA_HOME=/location/where/jdk/is/installed/ >> ~/.bash_profile. Most probably the JDK is installed in /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk. But you can execute echo $(/usr/libexec/java_home) to find the directory in which the JDK is installed.

NOTE: Every time you make a change to the .bash_profile you have to refresh bash so that it can make the changes so either close all terminal windows and reopen or execute source $HOME/.bash_profile.

Node and React Development

Use Homebrew to install node and npm(automatically downloaded on node installation).

brew install node
node -v
npm -v

To install create-react-app use npm to install it. The -g tag installs it globally. You can remove that to install it locally.

npm install -g create-react-app

iTerm2

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. Or using Homebrew, you can install iTerm2.

brew cask install iterm2

Upgrade packages

To see if any formulae of yours, are outdated:

brew outdated

Run the following to upgrade any one.

brew upgrade <formula>

[OPTIONAL] Modify look of terminal

It's totally a personal preference. I like my terminal to look a certain way. I also like having the git branch displayed in those directoried with git initialised. Add the lines below to the end of $HOME/.bash_profile file.

function parse_git_branch () {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
 
RED="\[\033[0;31m\]"
YELLOW="\[\033[0;33m\]"
GREEN="\[\033[0;32m\]"
NO_COLOR="\[\033[0m\]"
BLUE="\[\033[01;34m\]"
 
PS1="$YELLOW(\!)$GREEN \u:$BLUE\w$NO_COLOR\$(parse_git_branch)\n$RED\$ $NO_COLOR"

In the end it will look something like this

Notes for VS Code settings

If you saved your workspace settings in a gist, then install the 'Settings Sync' extension from the Marketplace and then follow the instructions there to download and sync your settings.

Notes for setup.sh

The script automatically will install Chrome, Spotify, Slack, VLC, Visual Studio Code, Alfred, Spectacle, Cheatsheet, Slack and Tunnelbear automatically.

It also installs tree extension for brew and wget for accessing links from the internet.

It also changes the folowing macOS settings:

#"Allowing text selection in Quick Look"
defaults write com.apple.finder QLEnableTextSelection -bool TRUE

#"Check for software updates daily, not just once per week"
defaults write com.apple.SoftwareUpdate ScheduleFrequency -int 1

#"Showing icons for hard drives, servers, and removable media on the desktop"
defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool true

#"Showing all filename extensions in Finder by default"
defaults write NSGlobalDomain AppleShowAllExtensions -bool true

#"Disabling the warning when changing a file extension"
defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false

#"Avoiding the creation of .DS_Store files on network volumes"
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true

#"Enabling snap-to-grid for icons on the desktop and in other icon views"
/usr/libexec/PlistBuddy -c "Set :DesktopViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist
/usr/libexec/PlistBuddy -c "Set :FK_StandardViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist
/usr/libexec/PlistBuddy -c "Set :StandardViewSettings:IconViewSettings:arrangeBy grid" ~/Library/Preferences/com.apple.finder.plist

#"Setting screenshots location to ~/Pictures/Screenshots"
defaults write com.apple.screencapture location -string "$HOME/Pictures/Screenshots"

#"Setting screenshot format to PNG"
defaults write com.apple.screencapture type -string "png"

#"Use `~/Downloads/Incomplete` to store incomplete downloads"
defaults write org.m0k.transmission UseIncompleteDownloadFolder -bool true
defaults write org.m0k.transmission IncompleteDownloadFolder -string "$HOME/Downloads/Incomplete"
``
#!/bin/bash
# Development and basic software setup for macOS
echo -e "\033[0;36m\033[0m"
echo -e "\033[0;36m------------------------------------------------------------\033[0m"
echo -e "\033[0;36mWelcome. This is a setup that will allow you to setup your \033[0m"
echo -e "\033[0;36mmacos machine as you see fit with all the latest technologies.\033[0m"
echo -e "\033[0;36mWe will use 'HomeBrew' to install all the softwares and dependen-\033[0m"
echo -e "\033[0;36mcies that you might want.\033[0m"
echo -e "\033[0;36m\033[0m"
read -p "Shall we continue? [Y/n] " proceed_check
if [[ $proceed_check == 'n' ]] || [[ $proceed_check == 'N' ]]
then
echo -e "\033[0;33mExiting...\033[0m"
echo -e "\033[0;36m------------------------------------------------------------\033[0m"
echo
else
apps=()
versions=()
echo -e "\033[0;36m------------------HOMEBREW INSTALLATION---------------------\033[0m"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
echo -e "\033[0;36mSetting brew in your PATH\033[0m"
echo 'PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile
echo -e "\033[0;36mUpdating HomeBrew\033[0m"
brew update
apps+=('HomeBrew ')
brew_result=$(brew --version)
versions+=("v${brew_result:9:6}")
echo -e "\033[0;36mTapping into Cask to install visual applications\033[0m"
brew tap caskroom/cask
echo -e "\033[0;36m------------------------------------------------------------\033[0m"
echo -e "\033[0;36m------------------INSTALLING BASIC APPS----------------------\033[0m"
echo -e "\033[0;36mInstalling the following apps by default\033[0m"
echo -e "\033[0;36m(Alfred, Spectacle, Cheatsheet, Google Chrome, VLC, iTerm2 and Transmission)\033[0m"
brew cask install alfred spectacle cheatsheet google-chrome vlc iterm2 transmission
echo -e "\033[0;36mInstalling zsh and Oh-My-Zsh\033[0m"
brew install zsh
apps+=('ZSH ')
zsh_result=$(zsh --version)
versions+=("v${zsh_result:4:6}")
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
echo -e "\033[0;36mSetting zsh as the default shell\033[0m"
chsh -s $(which zsh)
echo -e "\033[0;36m---------------------CONFIGURING GIT-------------------------\033[0m"
brew install git
apps+=('Git ')
git_result=$(git --version)
versions+=("v${git_result:12:6}")
read -p "Please specify directory where you downloaded 'dotfiles/': (wrt to ~)" download_directory
cd ~/Desktop
mkdir GitHub Projects
cd GitHub
mv /Users/$USER/download_directory/dotfiles .
ln dotfiles/.global_gitignore ~
ln dotfiles/.gitconfig ~
echo -e "\033[0;36m---------------ADDING ADDITIONAL PACKAGES-------------------\033[0m"
echo -e "\033[0;36mInstalling tree, wget, curl and htop\033[0m"
brew install tree wget curl htop
echo -e "\033[0;36m------------------------LANGUAGES---------------------------\033[0m"
echo -e "\033[0;36m-------------------------PYTHON3----------------------------\033[0m"
read -p "Would you like to install Python3? [Y/n] " python_check
if [[ $python_check == 'n' ]] || [[ $python_check == 'N' ]]
then
echo -e "\033[0;33mSkipping Python3 installation....\033[0m"
else
echo -e "\033[0;36mLatest Python3 installation....\033[0m"
brew install python
apps+=('Python3 ')
python_result=$(python3 --version)
versions+=("v${python_result:7:6}")
echo -e "\033[0;36m'venv' comes preinstalled with python3.5 and above\033[0m"
pip3 install python3-venv
read -p "Would you also like to install the jupyter package? [Y/n] " jupyter_check
if [[ $jupyter_check == 'n' ]] || [[ $jupyter_check == 'N' ]]
then
echo -e "\033[0;33mSkipping jupyter installation....\033[0m"
else
pip3 install jupyter
echo
fi
fi
echo -e "\033[0;36m---------------------------R------------------------------\033[0m"
read -p "Would you like to install R? [Y/n] " r_check
if [[ $r_check == 'n' ]] || [[ $r_check == 'N' ]]
then
echo -e "\033[0;33mSkipping R installation....\033[0m"
else
echo -e "\033[0;36mLatest R installation....\033[0m"
brew install r
apps+=('R ')
r_result=$(R --version)
versions+=("v${r_result:10:6}")
read -p "Would you also like to install RStudio? [Y/n] " studio_check
if [[ $studio_check == 'n' ]] || [[ $studio_check == 'N' ]]
then
echo -e "\033[0;33mSkipping RStudio installation....\033[0m"
else
brew cask install rstudio
echo
fi
fi
echo -e "\033[0;36m---------------------------NODE------------------------------\033[0m"
read -p "Would you like to install Node? [Y/n] " node_check
if [[ $node_check == 'n' ]] || [[ $node_check == 'N' ]]
then
echo -e "\033[0;33mSkipping node installation....\033[0m"
else
echo -e "\033[0;36mLatest node installation....\033[0m"
brew install node
apps+=('Node ')
versions+=($(node -v))
apps+=('NPM ')
versions+=("v$(npm -v)")
read -p "Would you also like to install Angular? [Y/n] " angular_check
if [[ $angular_check == 'n' ]] || [[ $angular_check == 'N' ]]
then
echo -e "\033[0;33mSkipping Angular installation....\033[0m"
else
echo -e "\033[0;36mLatest Angular installation....\033[0m"
npm install -g @angular.cli
apps+=("Angular ")
angular_result=$(ng --version)
versions+=("v${angular_result:349:6}")
fi
echo
echo -e "\033[0;36mCreate-React-App no longer needs to be installed.\033[0m"
echo -e "\033[0;36mRun 'npm create-react-app <project-name>' to install React locally and start building!\033[0m"
fi
echo -e "\033[0;36m---------------------------JAVA------------------------------\033[0m"
read -p "Would you like to install Java 12? [Y/n] " java_check
if [[ $java_check == 'n' ]] || [[ $java_check == 'N' ]]
then
echo -e "\033[0;33mSkipping java installation....\033[0m"
else
echo -e "\033[0;36mLatest java installation....\033[0m"
brew tap AdoptOpenJDK/openjdk
brew cask install adoptopenjdk12
apps+=("Java ")
java_result=$(java --version)
versions+=("v${java_result:5:7}")
echo -e "\033[0;36mAdding Java to PATH\033[0m"
echo 'export JAVA_HOME=$(/usr/libexec/java_home)' >> ~/.bash_profile
read -p "Would you also like to install Intellij-IDEA? [Y/n] " intellij_check
if [[ $intellij_check == 'n' ]] || [[ $intellij_check == 'N' ]]
then
echo -e "\033[0;33mSkipping Intellij-IDEA installation....\033[0m"
else
brew cask install intellij-idea
echo
fi
fi
echo -e "\033[0;36m----------------------CODE EDITORS-------------------------\033[0m"
echo -e "\033[0;36mPlease choose from the following options:\033[0m"
options=("VS Code" "Sublime Text 3" "Atom" "None of the above" "Quit code editor installation")
select opt in "${options[@]}"
do
case $opt in
"VS Code")
echo -e "\033[0;33mInstalling VS CODE\033[0m"
brew cask install visual-studio-code
;;
"Sublime Text 3")
echo -e "\033[0;33mInstalling Sublime text\033[0m"
brew cask install sublime-text
;;
"Atom")
echo -e "\033[0;33mInstalling Atom\033[0m"
brew cask install atom
;;
"None of the above")
echo -e "\033[0;33mSkipping code editor installation....\033[0m"
break
;;
"Quit code editor installation")
break
;;
*) echo -e "\033[0;31mInvalid option\033[0m";;
esac
done
echo -e "\033[0;36m----------------------DATABASES-------------------------\033[0m"
echo -e "\033[0;36mPlease choose from the following options:\033[0m"
options=("MySQL" "PostgreSQL" "MongoDB" "None of the above" "Quit database installation")
brew tap homebrew/services
select opt in "${options[@]}"
do
case $opt in
"MySQL")
echo -e "\033[0;36mInstalling MySQL5.7 and starting a service\033[0m"
brew install mysql@5.7
brew services start mysql@5.7
;;
"PostgreSQL")
echo -e "\033[0;36mInstalling PostgreSQL and starting a service\033[0m"
brew install postgres
brew services start postgresql
;;
"MongoDB")
echo -e "\033[0;36mInstalling MongoDB and starting a service\033[0m"
brew tap mongodb/brew
brew install mongodb-community@4.2
brew services start mongodb-community@4.2
;;
"None of the above")
echo -e "\033[0;33mSkipping database installation....\033[0m"
break
;;
"Quit database installation")
break
;;
*) echo -e "\033[0;31mInvalid option\033[0m";;
esac
done
echo -e "\033[0;36m---------------COMMUNICATION CHANNELS------------------\033[0m"
read -p "Would you like to install Slack? [Y/n] " slack_check
if [[ $slack_check == 'n' ]] || [[ $slack_check == 'N' ]]
then
echo -e "\033[0;33mSkipping slack installation....\033[0m"
else
echo -e "\033[0;36mLatest slack installation....\033[0m"
brew cask install slack
fi
read -p "Would you like to install Microsoft Teams? [Y/n] " teams_check
if [[ $teams_check == 'n' ]] || [[ $teams_check == 'N' ]]
then
echo -e "\033[0;33mSkipping Teams installation....\033[0m"
else
echo -e "\033[0;36mLatest Teams installation....\033[0m"
brew cask install microsoft-teams
fi
echo -e "\033[0;36m----------------------CLEANUP-------------------------\033[0m"
brew cleanup
# TODO
# adding version numbers to list and showing them at the end
echo -e "\033[0;36m--------------INSTALLED APPLICATIONS-----------------\033[0m"
for ((i=0;i<${#apps[@]};++i)); do
printf "%s : %s\n" "${apps[i]}" "${versions[i]}"
done
fi
install.packages('dplyr')
install.packages('stringi')
install.packages('stringr')
install.packages("tidyr")
install.packages("ggplot2")
install.packages('devtools')
install.packages('caret')
install.packages('rvest')
devtools::install_github("johndharrison/binman")
devtools::install_github("johndharrison/wdman")
devtools::install_github("ropensci/RSelenium")
install.packages('readr')
install.packages('roxygen2')
install.packages('kknn')
install.packages('Metrics')
install.packages('ISLR')
install.packages('rpart')
install.packages('MASS')
install.packages('mlbench')
install.packages('ROCR')
install.packages('randomForest')
install.packages('leaps')
install.packages('glmnet')

TODO

  • take user input
  • soft link for automation script and source it
  • transfer from bash to zsh
  • think about more stuff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment