This section is about installation and configuration of Opa. You can get a more detailed installation guide that includes how to build Opa from source on Opa's webpage (https://github.com/MLstate/opalang/wiki/Getting-started). This section will give us brief instructions on how to install Opa compiler, Node.js, and some required modules for Node.js.
Node.js (http://nodejs.org) is a platform for building fast and scalable network applications. It is the backend of Opa (since Opa 1.0.0). We need to install Node.js first before installing Opa. The following are the steps to install Node.js on various operating systems:
Mac OS: Following are the steps to install Node.js:
Download the latest
.pkg
package from http://nodejs.org/dist/latest/.Double-click on the package to install Node.js.
Ubuntu and Debian Linux: To install Node.js on Ubuntu and Debian Linux, type the following commands:
$sudo apt-get install python-software-properties $sudo add-apt-repository ppa:chris-lea/node.js $sudo apt-get update $sudo apt-get install nodejs npm
Tip
Downloading the example code files
You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
Windows: The following are the steps to install Node.js:
Download the latest
.msi
package from http://nodejs.org/dist/latest/.Double-click on the package to install Node.js on Windows.
Type the following commands to confirm your installation. If everything goes right, you will see the version information of Node.js and npm.
$ node -v $ npm –v
There are several modules that are required by Opa to run an application. Type the following command to install these modules:
$ npm install -g mongodb formidable nodemailer simplesmtp imap
The easiest solution for installing Opa is to download an installer from the Opa website (http://opalang.org/). You can also get the installer from Opa's GitHub repository (https://github.com/MLstate/opalang/downloads). At the time this book is being written, the latest version of Opa is 1.1.0.
Following are the steps to install Opa on various operating systems:
Mac OS X: Download the latest
.dmg
package and double-click on it to install. You will need the password of an administrative account.Ubuntu and Debian Linux: Download the latest
.deb
package and double-click on it to install. You can also install it with the following command line:$sudo dpkg –i opa-1.1.0.x86.deb
Windows: Download the latest
.exe
file and double-click on it to install. Note that only 64-bit packages are available for Windows at this time.Other Linux: To install Opa follow these steps:
Download the latest
.run
package for Linux.Go to the download folder and add an execution privilege to the downloaded file by running the following command:
$ chmod a+x opa-1.1.0.x64.run
Run the installing script:
$ sudo ./opa-1.1.0.x64.run
You can write Opa codes with any text editor you like, but a good editor can make coding easier. This section is about setting up editors you may commonly use. For now, Sublime Text is the most complete Integrated Development Environment (IDE) for Opa.
Sublime Text (http://www.sublimetext.com/) is a sophisticated text editor for code, markup, and prose. You can download and try Sublime Text for free from http://www.sublimetext.com/2.
There is an Opa plugin that offers syntax highlighting, code completion, and some other features. To install the plugin, follow these steps:
Get the plugin from https://github.com/downloads/MLstate/OpaSublimeText/Opa.sublime-package.
Move it to
~/.config/sublime-text2/Installed Packages/
(in Linux), or%%APPDATA%%\Sublime Text 2\Installed Packages\
(in Windows), or~/Library/Application Support/Sublime Text 2/Installed Packages
(in Mac).Start Sublime and check if the menu entry (View | Syntax | Opa) is present. If everything goes well, the file with the
.opa
extension should automatically have its syntax highlighted. If not, please make sure you are using the Opa plugin (View | Syntax | Opa). We can navigate to Edit | Line | Reindent to auto-indent the Opa code.
Vim (http://www.vim.org/) is a highly configurable text editor, freely available for many different platforms. The Opa installation package provides a mode for Vim at /usr/share/opa/vim/
(for Linux) or /opt/mlstate/share/opa/vim/
(for Mac OS). To enable Vim to detect Opa syntax, copy these files to your .vim
directory in your home folder (create it if it does not exist already):
On Linux, type the following command:
$cp –p /usr/share/opa/vim/* ~/.vim/
On Mac OS, type the following command:
$cp –p /opt/mlstate/share/opa/vim/* ~/.vim
On Mac OS X,
you can either use Aquamacs and the package installation will take care of it, or you should add the following line to your configuration file (which might be ~/.emacs
; create it if it does not exist already):
(autoload 'opa-classic-mode "/Library/Application Support/Emacs/site-lisp/opa-mode/opa-mode.el" "Opa CLASSIC editing mode." t) (autoload 'opa-js-mode "/Library/Application Support/Emacs/site-lisp/opa-mode/opa-js-mode.el" "Opa JS editing mode." t) (add-to-list 'auto-mode-alist '("\.opa$" . opa-js-mode)) (add-to-list 'auto-mode-alist '("\.js\.opa$" . opa-js-mode)) (add-to-list 'auto-mode-alist '("\.classic\.opa$" . opa-classic-mode))
On Linux, add the following lines to your configuration file:
(autoload 'opa-js-mode "/usr/share/opa/emacs/opa-js-mode.el" "Opa JS editing mode." t) (autoload 'opa-classic-mode "/usr/share/opa/emacs/opa-mode.el" "Opa CLASSIC editing mode." t) (add-to-list 'auto-mode-alist '("\.opa$" . opa-js-mode)) (add-to-list 'auto-mode-alist '("\.js\.opa$" . opa-js-mode)) (add-to-list 'auto-mode-alist '("\.classic\.opa$" . opa-classic-mode))
For Eclipse, the experimental plugin is available at https://github.com/MLstate/opa-eclipse-plugin.