Raku

From NixOS Wiki
Revision as of 11:44, 28 September 2025 by Dss (talk | contribs) (clarify instructions)
Jump to: navigation, search
Warning: This article is in an early stage.

Installing Rakudo and zef

Rakudo is the preferred implementation of Raku, and the zef the preferred module manager. Install them in a nix shell via

nix-shell -p rakudo zef

or install them permanently system-wide by adding pkgs.rakudo and pkgs.zef to your NixOS configuration file.

To create a Nix user environment on NixOS, run

nix-env -iA nixos.rakudo

(For environments or flakes on non-NixOS machines, different recommendations apply.[1])

No Nix packages currently exist for the Rakudo Star distribution, which bundles Rakudo with a collection of modules the language documentation. Thus, to use it, you need to download and compile it.[2] This way, you'll also always get the latest Rakudo version.

Making the Readline library available

When opening an interactive environment (by running rakudo, or its symlink raku, without arguments), you may get an error message like this:

I ran into a problem while trying to set up Readline: Could not instantiate role 'ReadlineBehavior'; exception details:
  Cannot locate native library 'libreadline.so.7': libreadline.so.7: cannot open shared object file: No such file or directory
  in method setup at [...]
Falling back to Linenoise (if present)
No line editor found.

You may want to exit first and `zef install Readline`, `zef install
Linenoise`, or `zef install Terminal::LineEditor` or install `rlwrap`
for a line editor before entering the REPL again.

With this error, Readline and its functions such as command history and cursor movement will not be available. To fix it, tell Raku the location of your Readline library by appending or prepending it to the environment variable $LD_LIBRARY_PATH. This can be done by adding the following code to your NixOS configuration (and then rebuilding and logging out and back in):

{
  #...
  environment.sessionVariables = rec {
    LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [ 
      pkgs.readline70
    ];
  };
  #...
}

For Nix shells, see for instance this example.

Resources

References