Skip to content

Instantly share code, notes, and snippets.

@adamreisnz
Last active February 27, 2023 11:58
Show Gist options
  • Save adamreisnz/4aef9f0f00da47199dbd to your computer and use it in GitHub Desktop.
Save adamreisnz/4aef9f0f00da47199dbd to your computer and use it in GitHub Desktop.
Setup Mac OS X work environment

Installing applications

Basic applications

Download and install the following applications:

Command line tools

Install the command line tools from console with the following command:

xcode-select --install

Follow the instructions and install the software.

Homebrew

Homebrew is a package manager for Mac. It can be used to install software packages and all their dependencies easily. Install Homebrew from console with the following command:

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

Check if everything is configured properly with:

brew doctor

If you get a message about chowning directories, run the following (on each of those directories):

sudo chown <username> <directory>

If you get a message about the PATH, add /usr/local/bin to your $PATH, either manually or by running the following command:

echo export PATH='/usr/local/bin:$PATH' >> ~/.bash_profile

Afterwards, open a new terminal window to make sure the new path has taken effect. Then check again if everything is configured properly using brew doctor.

Lastly, run an update:

brew update

Node.js

Install Node.js and npm package manager using an installer from the website:

Now create a folder for global packages:

mkdir "${HOME}/.npm-packages"

Configure npm by creating a ~/.npmrc file with the following contents:

init.author.name=<name>
init.author.email=<email>
init.author.url=<url>
prefix=${HOME}/.npm-packages

Add this folder to your $PATH variable in ~/.bash_profile:

NPM_PACKAGES="${HOME}/.npm-packages"
export PATH="$NPM_PACKAGES/bin:/usr/local/bin:$PATH"
export NODE_ENV=development

Alternatively, if you are using a shared bash configuration file on Dropbox, add the above to that configuration file and make sure your local ~/.bash_profile contains the following:

if [ -f ~/Dropbox/Work/bashrc.sh ]; then
  source ~/Dropbox/Work/bashrc.sh
fi

Update the system variables now:

source ~/.bash_profile

Next install the node version manager tool n using npm:

npm install -g n

Using this tool, you should now be able to install the latest version of node:

n latest

If you still run into permission problems, try troubleshooting with https://docs.npmjs.com/getting-started/fixing-npm-permissions

MongoDB

Install MongoDB using brew:

brew install mongodb

Create a directory for MongoDB's data:

mkdir -p ~/.mongodb-data

Run using the shell command:

mongod --dbpath ~/.mongodb-data

To start automatically when computer starts, create a launch deamon configuration file:

atom /Library/LaunchDaemons/org.mongo.mongod.plist

Past the following in it:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>org.mongo.mongod</string>
    <key>RunAtLoad</key>
    <true/>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/bin/mongod</string>
        <string>--dbpath</string>
        <string>/Users/<name>/.mongodb-data</string>
    </array>
    <key>HardResourceLimits</key>
    <dict>
      <key>NumberOfFiles</key>
      <integer>2048</integer>
    </dict>
    <key>SoftResourceLimits</key>
    <dict>
      <key>NumberOfFiles</key>
      <integer>2048</integer>
    </dict>
</dict>
</plist>

Next, run the following in your terminal:

sudo chown root:wheel /Library/LaunchDaemons/org.mongo.mongod.plist  
sudo launchctl load /Library/LaunchDaemons/org.mongo.mongod.plist  
sudo launchctl start org.mongo.mongod 

Project aliases

You can create aliases for projects using:

alias project="cd ~/Sites/some/long/path/to/project/"

Add these as needed to your ~/.bash_profile.

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