© Moritz Lenz 2020
M. LenzRaku Fundamentals https://doi.org/10.1007/978-1-4842-6109-5_2

2. Running Rakudo

Moritz Lenz1 
(1)
Fürth, Bayern, Germany
 

Before we start exploring the Raku language, you should have an environment where you can run Raku code. So you need to install Rakudo, currently the only actively developed Raku compiler. Or even better, install Rakudo Star, which is a distribution that includes Rakudo itself, a few useful modules, and a tool that can help you install more modules.

Installing Rakudo itself gives you just the compiler. It follows a monthly release cycle, so it allows you to keep up to date with the latest developments.

When you choose to install Rakudo Star, which is typically released every three months, you get a more stable base for development and some tools like a debugger and a module installer. You can use the module installer to make use of prepackaged software libraries that are included neither in Rakudo itself nor in Rakudo Star. Some examples in this book will require some modules from the ecosystem, so you should install Rakudo in a way that lets you use zef, the module installer.

The following sections discuss a few options for installing Rakudo Star. Choose whatever works for you.

The examples in this book use Rakudo 2020.01 and should work with this or any newer version of Rakudo, as long as it supports Raku version 6.d.

Note

The examples and source code used in this book can be accessed via the Download Source Code button at https://www.apress.com/9781484261088. You can also obtain the source code through git with this command: git clone https://github.com/apress/raku-fundamentals.git

2.1 Installers

You can download installers from https://rakudo.org/star for Mac OS (.dmg) and Windows (.msi). After download, you can launch them, and they walk you through the installation process.

Prebuilt Linux packages are available from https://github.com/nxadm/rakudo-pkg/releases/ for Debian, Ubuntu, CentOS, and Fedora.

In both cases, use version 202.01 to get the best compatibility with the examples used in this book.

Note that Rakudo is not relocatable, which means you have to install to a fixed location that was decided by the creator of the installer. Moving the installation to a different directory is not possible.

On Windows, the installer (Figure 2-1) offers to add C: akudoin and C: akudoshareperl6sitein to your PATH environment . You should choose that option, as it allows you to execute Raku (and programs that the module installer installs on your behalf) without specifying full paths.
../images/449994_2_En_2_Chapter/449994_2_En_2_Fig1_HTML.jpg
Figure 2-1

The Rakudo Star installer consists of four easy screens

2.2 Docker

On platforms that support Docker, you can pull an existing Docker container from the docker hub:
$ docker pull rakudo-star:2020.01
Then you can get an interactive Rakudo shell with this command:
$ docker run -it rakudo-star:2020.01 raku
But that alone won’t work for executing scripts, because the container has its own separate file system. To make scripts available inside the container, you need to tell Docker to make the current directory available to the container:
$ docker run -v $PWD:/raku -w /raku -it rakudo-star:2020.01 raku

The option -v $PWD:/raku instructs Docker to mount the current working directory ($PWD) into the container, where it’ll be available as /raku. To make relative paths work, -w /raku instructs Docker to set the working directory of the Rakudo process to /raku.

Since this command line starts to get unwieldy, I created an alias (this is Bash syntax; other shells might have slightly different alias mechanisms):
alias rd='docker run -v $PWD:/raku -w /raku -it rakudo-star:2020.01 raku'

I put this line into my ∼/.bashrc file so new shell instances have a rd command, short for “Raku docker.”

As a short test to see if it works, you can run
$ rd -e 'say "hi"'
hi

If you go the Docker route, use the rd alias instead of raku to run scripts.

2.3 Building from Source

To build Rakudo Star from source, you need make, the GNU C Compiler1 (GCC), or clang and Perl 5 installed. This example installs into $HOME/opt/rakudo-star:
$ wget https://rakudo.org/dl/star/rakudo-star-2020.01.tar.gz
$ tar xzf rakudo-star-2020.01.tar.gz
$ cd rakudo-star-2020.01/
$ perl Configure.pl --prefix=$HOME/opt/rakudo-star --gen-moar
$ make install

You should have about 2GB of RAM available for the last step; building a compiler is a resource-intensive task.

You need to add paths to two directories to your PATH environment variable, one for Rakudo itself and one for programs installed by the module installer:
PATH=$PATH:$HOME/opt/rakudo-star/bin/:$HOME/opt/rakudo-star/share/perl6/site/bin

If you are a Bash user, you can put that line into your ∼/.bashrc file to make it available in new Bash processes.

2.4 Testing Your Rakudo Star Installation

You should now be able to run Perl 6 programs from the command line and ask Rakudo for its version:
$ raku --version
This is Rakudo version 2020.01 built on MoarVM version 2020.01.1
implementing Perl 6.d.
$ perl6 -e "say <hi>"
hi

If, against all odds, all of these approaches have failed to produce a usable Rakudo installation, you should describe your problem to the friendly Raku community, which can usually provide some help. https://raku.org/community/ describes ways to interact with the community.

2.5 Documentation

Rakudo itself has little documentation, since most of the interesting material is about the Raku language. But Rakudo does come with a summary of command-line options that you can access by calling raku --help.

The official place for Raku language documentation is at https://docs.raku.org/, which aims to provide both reference and tutorial-style material. Other good resources are listed at https://raku.org/resources/, many of which are created and maintained by members of the Raku community.

2.6 Summary

On most platforms, you can install Rakudo Star from prebuilt binary installers. Where this doesn’t work, Docker images are available. Finally, Rakudo Star can be built from its sources.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.23.127.197