Installing Lua locally

Learn how to install Lua locally to solve Exercism's exercises on your own machine


MacOS

First install Lua and Luarocks using Homebrew:

$ brew install lua luarocks

Then install the Busted testing framework for Lua:

$ luarocks install --local busted

Add ~/.luarocks/bin to your system $PATH

export PATH="$HOME/.luarocks/bin:$PATH"

Note that this is only temporary. To add permanently to your $PATH then you will have to add it to your .bashrc, .zshrc or config.fish depending on which shell you are using.

Then run your tests:

$ busted

Ubuntu

First install Lua and Luarocks using Apt:

$ sudo apt-get install lua5.4 liblua5.4-dev luarocks

Then install the Busted testing framework for Lua:

$ luarocks install --local busted

Add ~/.luarocks/bin to your system $PATH

export PATH="$HOME/.luarocks/bin:$PATH"

Note that this is only temporary. To add permanently to your $PATH then you will have to add it to your .bashrc, .zshrc or config.fish depending on which shell you are using.

Then run your tests:

$ busted

Windows 10: WSL

First you must enable WSL (Windows Subsystem for Linux) using PowerShell (Administrator):

PS> Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

This requires a reboot.

Next, install Ubuntu from the Microsoft Store, or download then install using PowerShell:

PS> curl.exe -L -o ubuntu1804.appx https://aka.ms/wsl-ubuntu-1804
PS> Add-AppxPackage .\ubuntu1804.appx; rm .\ubuntu1804.appx
PS> ubuntu1804

Then update your package list:

PS> wsl
$ sudo apt-get update

Now you are ready to install LuaRocks and Busted by following the Ubuntu instructions above.

Once done you can run your tests directly from any Windows command line:

C:\> wsl busted

Windows 10: Docker

Install Gitbash

This step is optional. You may have to tweak the following steps slightly if you prefer to use Windows' native CLI or another CLI.

Download here. Install Instructions here.

Install Docker

Follow the instructions to install Docker for Windows. Once you've finished installing, you can run the following command to ensure it's been installed correctly.

$ docker --version

You may encounter an error when trying to run Docker the first time.

cannot enable hyper-v service

If this occurs, you can follow these instructions to enable Hyper V. You may have to disable the setting, restart your computer and re-enable it after boot.

Install busted

Once you have Gitbash and Docker installed, you'll be able to install a busted 'container'.

In Gitbash run the following:

Pull down this widely used Docker container by running the following:

$ docker pull imega/busted

Create a function so you don't have to type the whole command every time. Add this to your .bashrc:

dbusted() { docker run --rm -t -v "/$@":/data imega/busted; }

Now, in your CLI, you can navigate into the directory you want to run your tests in. Run the following:

$ dbusted $PWD

You should see the output from your busted tests.