work and nonwork

Getting Started with PureScript

November 12, 2019

Today I’m setting up a PureScript development environment and I’m taking the opportunity to write a quick getting started guide for developers who do not yet even have a Node.js environment set up.

I’m working on Debian 10, but these instructions should work for most Linux distributions. Mac users will mostly likely need to decide for themselves how to best install Node.js. I have seen the use of brew recommended in some places, but I’ve also seen it recommended against in other places!

Getting Node.js

There are a lot of options here, and from looking at official documentation I do not get the feeling that there is any de facto standard. In any case, after taking a look at this, here’s what I did:

Get the LTS Linux Binaries

Official source here.

Create a Directory to Hold the Unpacked Archive

$ sudo mkdir -p /usr/local/lib/nodejs

Unpack the Archive into the New Directory

# replace $VERSION-$DISTRO to match the name of the actual file!
$ sudo tar -xvf node-$VERSION-$DISTRO.tar.xz -C /usr/local/lib/nodejs

Change the Prefix for Globally Installed Packages

I prefer that packages installed via npm install -g are installed under the user’s home directory as:

  • I avoid polluting the global system and affecting other users
  • I avoid having to use sudo for an operation for which root privileges should not (in my opinion) be necessary.

Therefore, if it does not exist, create the file ~/.npmrc and add the following:

prefix=~/.npm-global

All packages installed with npm install -g will now be installed under $HOME/.npm-global for the user.

(See here for official documentation.)

Alter the Path

Add the following to the end of ~/.bashrc to get node related binaries in the path:

# Change the path below to reflect the actual version of node that you installed
export PATH=/usr/local/lib/nodejs/node-v12.13.0-linux-x64/bin:$PATH
export PATH=$HOME/.npm-global/bin:$PATH

Note: It is necessary to restart the terminal to get the above modification to the path into effect.

Get PureScript

The rest of the process is covered in the official PureScript docs here, but here are my notes:

Install the PureScript Compiler

$ npm install -g purescript

The first time I tried this I got an error that a library called libtinfo.so.5 could not be found. A quick google for libtinfo Debian showed me that the library is made available by package libtinfo5. I was able to resolve the issue with a simple sudo apt install libtinfo5, but of course every distro and environment will be different.

Install the Tools

Pulp is the build tool, and Bower is used as a package manager.

$ npm install -g pulp bower

Create a New Project

$ mkdir hello-purescript && cd hello-purescript && pulp init

Build and Test

$ pulp build
$ pulp test

Next Steps

To continue learning about PureScript and project package management, please consult the official PureScript gettting started guide!

Have fun!


Chris Schappert

I'm Chris Schappert, a software developer living and working in Tokyo. Follow me on GitHub and LinkedIn.