In this section we are going to install or update three package managers -- software that downloads libraries and/or executable programs that we rely on to build the WebApp (npm, Homebrew, and pip). We are also going install or update two language interpreters (Node and Python):
- Node: "Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine." Node allows you to run JavaScript outside of a browser, at the command line, or on a server. Many of our build processes run on Node.
- npm: NPM is the Node package manager (installer of software modules), and is automatically installed with Node. It can be updated separately and occasionally this might be necessary. NPM is used extensively in WebApp to update most of the opensource JavaScript libraries that we leverage.
- Python: Python is a popular interpreted language that is used most often as a server side language for handling APIs or simple web applications. The WeVoteServer, our API server, is written in Python.
- Homebrew: Homebrew, or simply
brew
at the command line, is "the missing package manager for MacOS." It is the package manager that is often the first one installed, and can be used to install other package managers and libraries. - pip: "pip is [Python's] preferred installer program. Starting with Python 3.4, it is included by default with the Python binary installers." The Mac's built-in Python distibution does not include pip, so we need to install it manually.
- nodeenv: "nodeenv (Node.js virtual environment) is a tool to create isolated Node.js environments. It creates an environment that has its own installation directories, that doesn't share libraries with other Node.js virtual environments."
- node-sass: "Node-sass is a library that provides binding for Node.js to LibSass, the C version of the popular stylesheet preprocessor, Sass." We write styles in Sass (scss files), and the node-sass pre-processor compiles them to css on the fly, before the excution of the WebApp begins.
- Ruby: "A dynamic, open source programming language with a focus on simplicity and productivity." Ruby is yet another interpreted language, that comes pre-installed on the Mac. We use it to install Homebrew.
Install Homebrew, and then install Python:
$ cd ~
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
$ brew install python
Next use Python to install pip:
$ curl https://bootstrap.pypa.io/get-pip.py
Now install nodeenv with pip. Install nodeenv globally. (For instructions installing it locally, see: https://github.com/ekalinin/nodeenv):
$ sudo -H pip3 install nodeenv
If you are already using Node and npm, confirm that your installation is at least at these minimum versions:
$ node -v
v10.12.0
$ npm -v
6.4.1
If you find that your Mac, does not have Node installed, install it with brew. (If you want to have
a fresh install of Node you can brew unlink node
first.) A fresh or initial install of Node,
will automatically install the latest version of npm.
$ brew install node
$ node -v
$ npm -v
Create a place for your WebApp virtual environment to live on your hard drive. We recommend installing it away from the WebApp source code:
$ mkdir /Users/<YOUR NAME HERE>/NodeEnvironments/
$ cd /Users/<YOUR NAME HERE>/NodeEnvironments/
Now create a new virtual environment in that 'NodeEnvironments' folder. This can take many minutes.
$ nodeenv WebAppEnv
Now activate this new virtual environment:
$ cd /Users/<YOUR NAME HERE>/NodeEnvironments/WebAppEnv/
$ . bin/activate
Note that you will need to do the step above every time before you start local development. Once you have activated this virtual Node environment, it will persist in the current Terminal tab even as you navigate to different folders (e.g., the WeVote WebApp folder). You'll see that each line on the Terminal starts with (WebAppEnv)
while the virtual environment is in effect. You can read more about nodeenv here.
Just to be safe, rebuild node-sass:
(WebAppEnv) $ npm rebuild node-sass
(WebAppEnv) $ /usr/local/bin/node -v
v9.10.1
Export your path to the local environment (append the /usr/local/bin
path segment to the path that is used when in the WebAppEnv):
(WebAppEnv) $ export PATH="/usr/local/bin:$PATH"
Mac users are now done with this page, go on to the next section: Bringing Code to Your Machine
Create a place to put all of the code from Github:
$ mkdir /Users/<YOUR NAME HERE>/MyProjects/