Dev Environment – Linux

What we will try to accomplish

We’re going to walk step-by-step through setting up your Linux machine to use a development environment like the one I use.

This one is coming first primarily because I use Linux myself, and also because it’s one of the easier environments to get set up. I am using Ubuntu 20.04 as the example, but the steps for other distributions will be similar, apart from the system package manager steps.

What are we installing, actually?

  • basic build tools
  • Lua5.1
  • LuaRocks
  • Luaformatter
  • Visual Studio Code
  • docker
  • muddler

Let’s get started

I recommend doing this while your system is up to date, but it isn’t necessary. I used a virtualbox image from osboxes.org to ensure it works on a clean install and to get the screenshots, so the username will be osboxes throughout the demonstration.

Build tools and dependencies

# Make sure you have the latest package information
sudo apt-get update
# Install dependencies. Up to cmake are for luarocks/luaformatter. After that will be needed by docker's install later.
sudo apt-get install build-essential gcc git libreadline-dev lua5.1 liblua5.1-0-dev cmake apt-transport-https ca-certificates curl gnupg-agent software-properties-common
Installing system dependencies

LuaRocks

Next, we will install LuaRocks. We do not use the system version as it’s older, and Luaformat needs something newer.

# the wget is to download the archive file
wget https://luarocks.github.io/luarocks/releases/luarocks-3.9.0.tar.gz
download LuaRocks
# this extracts the file into its directory
tar zxvf luarocks-3.9.0.tar.gz
# Then we move into the directory
cd luarocks-3.9.0.tar.gz
# The provided configure script will determine where all the pieces luarock needs to build are kept on your system
./configure
extract and configure LuaRocks
# Then we build it
make
building LuaRocks
# And this installs the build files to your system
sudo make install
installing LuaRocks

After this you will need to edit your .bashrc file. If you are using a shell other than bash, this filename will be different, use the file appropriate to your shell. Add the following line to the end of the file, save, and quit.

PATH=$PATH:/usr/local/bin:$HOME/luarocks-3.5.0/lua_modules/bin

This adds /usr/local/bin and the luarocks directory in your homedir to your path, so that luarocks and the luarocks you install with it will be available in your path.

LuaFormatter

Close your current terminal and open a new one so the PATH change above will take effect before the next step.

sudo luarocks install --server=https://luarocks.org/dev luaformatter

It can take a moment, the series of pictures below gives you an idea of what you can expect. Do not worry about the attribute warnings, warnings are usually nothing to worry about.

LuaRocks will take care of downloading, compiling, and installing LuaFormatter for you when you hit enter.

I recommend you download my luaformatter config file, though this step is optional and you can format your code how you like, this will provide a starting place that has your code looking like mine, anyhow.

cd $HOME
wget https://raw.githubusercontent.com/demonnic/MDK/master/.luaformatter
downloading luaformatter config

VSCode

You can download Visual Studio Code from https://code.visualstudio.com/Download . Select the version which is right for your linux, in this case the .deb. Once it is downloaded, double click it to install.

Once it is installed, open it and go to the extensions tab.

First install sumneko.lua

Then install the koihik.vscode-lua-format

If you downloaded my luaformatter config file, hit ctrl+shift+p and type ‘settings’, then click “Preferences: Open Settings (JSON)”.

Open settings

This will bring up the settings file for vscode. You want to add the following line to it at the top, just below the first {, with <user> replaced by your username.

    "vscode-lua-format.configPath": "/home/<user>/.luaformatter",
Add config for luaformatter

The order of the entries doesn’t really matter, but this way it should definitely be in the right place and not accidentally nested in something else.

Docker

Add docker’s GPG key and ubuntu repository to your system

# Download and install the GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
# add Docker repository to repository list
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
# update package information
sudo apt-get update
Setup docker repository

Install docker

# install docker
sudo apt-get install docker-ce docker-ce-cli containerd.io
# add docker group - this failed for me because the group
# already existed, but it doesn't hurt to run it if the group
# already exists, so I included it.
sudo groupadd docker
# and add yourself to it
sudo usermod -aG docker $USER

You can verify it’s working by running their hello world image. First, close your terminal and open a new one so it sees your new group membership. I have occasionally had to reboot my computer for this to take effect, so if the following fails, try adding ‘sudo’ in front of it. I recommend rebooting though.

docker run hello-world
hello world!

Muddler

Since we installed docker, this is now very simple

docker pull demonnic/muddler:latest
pulling muddler image

You can now use docker to run muddler to create your Mudlet packages. To aid in this, you may want to download the ‘muddle’ script and place it in your path.

wget https://raw.githubusercontent.com/demonnic/muddler/master/muddle
chmod +x muddle
sudo mv muddle /usr/local/bin
Installing wrapper script for ease of use

Congratulations! You now have everything you need to replicate the essential pieces of my development environment for Mudlet scripts. I opened up the MDK project so you could see what it looks like at the end.

emco.lua from the MDK in new dev env

For follow up, if you want to get rid of all the yellow squiggles you may want to follow the instructions HERE. And to save some typing, add the snippets for vscode for Mudlet I maintain HERE. But both of these steps are optional and while they will improve your experience they are not required.

2 Comments on “Dev Environment – Linux

  1. Thanks for the very detailed instructions.
    Even though I use Mudlet for a while now and made few packages myself I never got around to use muddler.
    Thanks to your instructions (which make the whole process so much easier\faster) that will change now 😉

    • Absolutely welcome, and thanks for stopping by! I’m happy to hear the format seems to be good for getting the directions across. Was a little worried I might have gone overboard with the pictures. =)