MacOS Developer Setup for React, React Native, Node JS and Cassandra Development

This dopcument described setting up the development environment for work with Universal Relay Boilerplate and Rebar based projects, including:

Portions of this document are based on the following resources:

Install XCode

XCode is required for iOS app development. Also, some of the tools provided by XCode are used by the other developer tools that will be needed.

Install XCode from the Mac App Store.

Install Homebrew

Homebrew is a package manager for Mac.

Use the following command to install Homebrew:

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

The result of a successful installation looks like this:

==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
==> The following new directories will be created:
/usr/local/Cellar
/usr/local/Homebrew
/usr/local/Frameworks
/usr/local/bin
/usr/local/etc
/usr/local/include
/usr/local/lib
/usr/local/opt
/usr/local/sbin
/usr/local/share
/usr/local/share/zsh
/usr/local/share/zsh/site-functions
/usr/local/var

Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/mkdir -p /usr/local/Cellar /usr/local/Homebrew /usr/local/Frameworks /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/sbin /usr/local/share /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var
Password:
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/Cellar /usr/local/Homebrew /usr/local/Frameworks /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/sbin /usr/local/share /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var
==> /usr/bin/sudo /bin/chmod 755 /usr/local/share/zsh /usr/local/share/zsh/site-functions
==> /usr/bin/sudo /usr/sbin/chown alex /usr/local/Cellar /usr/local/Homebrew /usr/local/Frameworks /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/sbin /usr/local/share /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var
==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/Cellar /usr/local/Homebrew /usr/local/Frameworks /usr/local/bin /usr/local/etc /usr/local/include /usr/local/lib /usr/local/opt /usr/local/sbin /usr/local/share /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var
==> /usr/bin/sudo /bin/mkdir -p /Users/alex/Library/Caches/Homebrew
==> /usr/bin/sudo /bin/chmod g+rwx /Users/alex/Library/Caches/Homebrew
==> /usr/bin/sudo /usr/sbin/chown alex /Users/alex/Library/Caches/Homebrew
==> /usr/bin/sudo /bin/mkdir -p /Library/Caches/Homebrew
==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew
==> /usr/bin/sudo /usr/sbin/chown alex /Library/Caches/Homebrew
==> Downloading and installing Homebrew...
remote: Counting objects: 4140, done.
remote: Compressing objects: 100% (2757/2757), done.
remote: Total 4140 (delta 2102), reused 2661 (delta 1236), pack-reused 0
Receiving objects: 100% (4140/4140), 2.42 MiB | 785.00 KiB/s, done.
Resolving deltas: 100% (2102/2102), done.
From https://github.com/Homebrew/brew
 * [new branch]      master     -> origin/master
 * [new tag]         0.1        -> 0.1
 * [new tag]         0.2        -> 0.2
 * [new tag]         0.3        -> 0.3
 * [new tag]         0.4        -> 0.4
 * [new tag]         0.5        -> 0.5
 * [new tag]         0.6        -> 0.6
 * [new tag]         0.7        -> 0.7
 * [new tag]         0.7.1      -> 0.7.1
 * [new tag]         0.8        -> 0.8
 * [new tag]         0.8.1      -> 0.8.1
 * [new tag]         0.9        -> 0.9
 * [new tag]         0.9.1      -> 0.9.1
 * [new tag]         0.9.2      -> 0.9.2
 * [new tag]         0.9.3      -> 0.9.3
 * [new tag]         0.9.4      -> 0.9.4
 * [new tag]         0.9.5      -> 0.9.5
 * [new tag]         0.9.8      -> 0.9.8
 * [new tag]         0.9.9      -> 0.9.9
 * [new tag]         1.0.0      -> 1.0.0
 * [new tag]         1.0.1      -> 1.0.1
 * [new tag]         1.0.2      -> 1.0.2
 * [new tag]         1.0.3      -> 1.0.3
 * [new tag]         1.0.4      -> 1.0.4
 * [new tag]         1.0.5      -> 1.0.5
 * [new tag]         1.0.6      -> 1.0.6
 * [new tag]         1.0.7      -> 1.0.7
 * [new tag]         1.0.8      -> 1.0.8
 * [new tag]         1.0.9      -> 1.0.9
 * [new tag]         1.1.0      -> 1.1.0
 * [new tag]         1.1.1      -> 1.1.1
HEAD is now at 84b3c57 Merge pull request #1581 from MikeMcQuaid/rubocop-exclude-vendor
==> Homebrew has enabled anonymous aggregate user behaviour analytics
Read the analytics documentation (and how to opt-out) here:
  https://git.io/brew-analytics
==> Tapping homebrew/core
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'...
remote: Counting objects: 3768, done.
remote: Compressing objects: 100% (3657/3657), done.
remote: Total 3768 (delta 14), reused 309 (delta 1), pack-reused 0
Receiving objects: 100% (3768/3768), 3.01 MiB | 1.36 MiB/s, done.
Resolving deltas: 100% (14/14), done.
Checking connectivity... done.
Tapped 3646 formulae (3,795 files, 9.4M)
==> Cleaning up /Library/Caches/Homebrew...
==> Migrating /Library/Caches/Homebrew to /Users/alex/Library/Caches/Homebrew...
==> Deleting /Library/Caches/Homebrew...
Already up-to-date.
==> Installation successful!

==> Homebrew has enabled anonymous aggregate user behaviour analytics.
Read the analytics documentation (and how to opt-out) here:
  https://git.io/brew-analytics

==> Next steps:
- Run `brew help` to get started
- Further documentation:
    https://git.io/brew-docs

Test if homebrew is ready for use:

brew doctor

If your installation is complete, the result will look like:

Your system is ready to brew.

Install git

Git is a source control tool used to manage URB and Rebar versions.

Install git using homebrew:

brew update
brew install git

A successful installation will produce results similar to this:

$ brew update
Already up-to-date.
$ brew install git
==> Downloading https://homebrew.bintray.com/bottles/git-2.10.2.sierra.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring git-2.10.2.sierra.bottle.1.tar.gz
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

zsh completion has been installed to:
  /usr/local/share/zsh/site-functions

Emacs Lisp files have been installed to:
  /usr/local/share/emacs/site-lisp/git
==> Summary
🍺  /usr/local/Cellar/git/2.10.2: 1,445 files, 31.8M

In order to verify that git is working well use the version command:

git --version

If git is working properly, it will report the current version similar to this:

git version 2.10.2

Install Atom Editor

Atom is a text editor which is best suited for working with URB and Rebar. Among other things, the To Do module and the beautification module are a good way to deal with the source code.

Install Atom. Within Atom, install the following packages:

Install Node.js

URB and Rebar use Node.js servers. Also, the webpack and react native tools use Node.js.

Install NVM

In order to install Node.js we will use the Node Version Manager. In order to install NVM, do:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash

A typical execution result is as follows:

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                               Dload  Upload   Total   Spent    Left  Speed
100 10250  100 10250    0     0  25044      0 --:--:-- --:--:-- --:--:-- 25061
=> Downloading nvm from git to '/Users/alex/.nvm'
=> Cloning into '/Users/alex/.nvm'...
remote: Counting objects: 6001, done.
remote: Compressing objects: 100% (21/21), done.
remote: Total 6001 (delta 10), reused 0 (delta 0), pack-reused 5980
Receiving objects: 100% (6001/6001), 1.70 MiB | 1.73 MiB/s, done.
Resolving deltas: 100% (3735/3735), done.
* (HEAD detached at v0.32.1)
master
=> Compressing and cleaning up git repository
Counting objects: 6001, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5966/5966), done.
Writing objects: 100% (6001/6001), done.
Total 6001 (delta 3951), reused 1827 (delta 0)

=> Profile not found. Tried  (as defined in $PROFILE), ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile.
=> Create one of them and run this script again
=> Create it (touch ) and run this script again
 OR
=> Append the following lines to the correct file yourself:

export NVM_DIR="/Users/alex/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm
=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="/Users/alex/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm

After this make execute:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm

To verify the installation, execute:

nvm --version

which should display the current version of nvm, like:

0.32.1

Install Node.js

Use NVM to install Node.js 8.4:

nvm install node 8.4.0

A successful installation will display:

######################################################################## 100.0%
Computing checksum with shasum -a 256
Checksums matched!
Now using node v8.4.0 (npm v5.3.0)
Creating default alias: default -> node (-> v8.4.0)

The installation should also include the appropriate version of NPM. In order to verify this run:

npm --version

which should display a version like:

5.3.0

Install Watchman

Watchman is a service that watches for file changes and triggers actions based on those changes. It is used by Node.js and React tools like nodemon, react hot reload and react native. Install Watchman by running:

brew install watchman

A typical installation would produce result similar to:

Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
cheat       gibo        grib-api    jasper      libicns     netpbm      notmuch     ttyd        vim         youtube-dl
dcraw       gofabric8   hunspell    javarepl    libraw      node-build  snzip       ufraw       vultr

==> Installing dependencies for watchman: pcre
==> Installing watchman dependency: pcre
==> Downloading https://homebrew.bintray.com/bottles/pcre-8.39.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring pcre-8.39.sierra.bottle.tar.gz
🍺  /usr/local/Cellar/pcre/8.39: 203 files, 5.4M
==> Installing watchman
==> Downloading https://homebrew.bintray.com/bottles/watchman-4.7.0.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring watchman-4.7.0.sierra.bottle.tar.gz
==> Using the sandbox
🍺  /usr/local/Cellar/watchman/4.7.0: 21 files, 429K

Install additional Node.js modules

Yarn is a package manager which is used in place of NPM in Universal Relay Boilerplate and Rebar projects:

npm install -g yarn

The react native CLI utility is installed by:

npm install -g react-native-cli

In order to update react-native, react-native-git-upgrade can be used for best results:

npm install -g react-native-git-upgrade

Install Java 8 JDK

Java is necessary for both Android development and running Cassandra.

Install the Java JDK from Oracle's website. In order to test the installation run:

java -version

which should produce result similar to:

java version "1.8.0_112"
Java(TM) SE Runtime Environment (build 1.8.0_112-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b16, mixed mode)

Install Elassandra in user space (local copy)

If you desire to install Cassandra separately, skip over to the Cassandra installation instructions.

Download Elassandra:

mkdir -p ~/opt/packages
cd $_
curl -L -O https://github.com/strapdata/elassandra/releases/download/v5.5.0.1/elassandra-5.5.0.tar.gz

A successful download should result in something like:

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                               Dload  Upload   Total   Spent    Left  Speed
100   613    0   613    0     0   1592      0 --:--:-- --:--:-- --:--:--  1596
100 71.5M  100 71.5M    0     0  6560k      0  0:00:11  0:00:11 --:--:-- 7665k

Extract Elassandra:

tar -xzf elassandra-5.5.0.tar.gz
ln -s ~/opt/packages/elassandra-5.5.0 ~/opt/elassandra

After that add Elassandra to your path and source the profile:

vi ~/.bash_profile

Paste the following into your .bash_profile file.

# include locally installed Elassandra in PATH
if [ -d "$HOME/opt" ]; then
    PATH="$PATH:$HOME/opt/elassandra/bin"
fi

Source your .bash_profile file by running:

cd ~
source .bash_profile

Install Cassandra in user space (local copy)

If you do not choose to use Elassandra, follow the instructions below for installing Cassandra.

These installation steps show how to install a local copy of Cassandra. The benefits of a local copy are that you do not need root or sudo to install Cassandra, updating versions is quick and easy, and you can control how/when to install updates.

Please notice that the features of Rebar/URB require version 3.9.

In order to install execute the following commands:

mkdir -p ~/opt/packages
cd $_
curl -O http://apache.claz.org/cassandra/3.9/apache-cassandra-3.9-bin.tar.gz

A successful download should result in something like:

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                               Dload  Upload   Total   Spent    Left  Speed
100 29.5M  100 29.5M    0     0  3996k      0  0:00:07  0:00:07 --:--:-- 4442k

Follow up with commands to extract the Cassandra files and create a link:

gzip -dc apache-cassandra-3.9-bin.tar.gz | tar xf -
ln -s ~/opt/packages/apache-cassandra-3.9 ~/opt/cassandra

Create folders used by Cassandra:

mkdir -p ~/opt/cassandra/data/data
mkdir -p ~/opt/cassandra/data/commitlog
mkdir -p ~/opt/cassandra/data/saved_caches
mkdir -p ~/opt/cassandra/logs

After that add Cassandra to your path and source the profile:

vi ~/.bash_profile

Paste the following into your .bash_profile file.

# include locally installed Cassandra in PATH
if [ -d "$HOME/opt" ]; then
    PATH="$PATH:$HOME/opt/cassandra/bin"
fi

Source your .bash_profile file by running:

cd ~
source .bash_profile

Configure Cassandra/Elassandra to use less memory

Very often on a development machine it would be natural to reduce the amount of memory that Cassandra is using. While going below the minimum settings for memory is not advised for production instances, as far as development goes it is perfectly fine. In the example below the total amount of memory for Cassandra will be below 1GB, which is enough for basic development with Elassandra.

In ~/opt/cassandra/conf/cassandra-env.sh (or ~/opt/elassandra/conf/cassandra-env.sh) modify:

# Override these to set the amount of memory to allocate to the JVM at
# start-up. For production use you may wish to adjust this for your
# environment. MAX_HEAP_SIZE is the total amount of memory dedicated
# to the Java heap. HEAP_NEWSIZE refers to the size of the young
# generation. Both MAX_HEAP_SIZE and HEAP_NEWSIZE should be either set
# or not (if you set one, set the other).
#
# The main trade-off for the young generation is that the larger it
# is, the longer GC pause times will be. The shorter it is, the more
# expensive GC will be (usually).
#
# The example HEAP_NEWSIZE assumes a modern 8-core+ machine for decent pause
# times. If in doubt, and if you do not particularly want to tweak, go with
# 100 MB per physical CPU core.

MAX_HEAP_SIZE="600M"
HEAP_NEWSIZE="300M"

Running Cassandra/Elassandra

Cassandra can be started by running:

cassandra -f

Elassandra can be started by running:

cassandra -f -e

In a different terminal window run cqlsh, a typical result when installation has been successful would be similar to:

cqlsh
Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.9 | CQL spec 3.4.0 | Native protocol v4]
Use HELP for help.

Running elastic search

Elastic search can be tested by running:

curl -X GET http://localhost:9200/

A typical output would be:

{
  "name" : "127.0.0.1",
  "cluster_name" : "Test Cluster",
  "cluster_uuid" : "55624ace-068a-4dbd-9ee5-cae2d81e59e6",
  "version" : {
    "number" : "2.4.5",
    "build_hash" : "${buildNumber}",
    "build_timestamp" : "2017-06-22T14:41:58Z",
    "build_snapshot" : false,
    "lucene_version" : "5.5.4"
  },
  "tagline" : "You Know, for Search"
}

Facebook SDK

If your react native application is utilizing Facebook login, download the Facebook SDK and place it in:

 ~/Documents/FacebookSDK

Android Studio

For Android development, download Android Studio it will also include the Android SDK. This will allow to run applications using react-native CLI as well as from within Studio.

Flow

Flow is used for static type checking of JavaScript. While it can be installed locally in a project, in order to use it securely with Atom/Nuclide, a global installation is a better option. Install it globally with the following command:

npm install -g flow-bin

In order to verify if flow is installed, it can be run. When run in a non-project folder, it would issue the following message:

Could not find a .flowconfig in . or any of its parent directories.
See "flow init --help" for more info