How to install packages

In a Nextjournal notebook, you can install or download anything that can be installed on a Linux machine. Here, we'll show you how to install packages with Bash, and how to use your installed/downloaded content from other code cells.

Step 1: add a Bash cell

Let's start by adding a Bash cell.

If you already have other, non-Bash runtimes present in your notebook, go here. Otherwise, keep reading.

Adding the Bash cell will create a Bash runtime: a process running in a Docker container (the Nextjournal environment).

This information can also be seen in the code cell itself:

Step 2: install the package(s)

Since having a Bash runtime is essentially like running Ubuntu, you can install packages from files, via dpkg, or fetch them from repositories with apt.

In this case, let's install a Python library via pip. The pip package installer is already included in our base Bash runtime.

Step 3: use the package from another code cell

Add a code cell in the programming language that you want to work with. Here, we'll add a Python code cell.

By doing so, we add a Python runtime, completely isolated and independent from our Bash runtime. This is intentional - curious as to why? Check this out.

However, to use the installed package within our Python environment, we need our Bash code cell to share the Python cell's runtime (so that they have the same file system).

To this end, we go back to the Bash cell, and change its runtime to the Python runtime via the “Options” menu at the left of the cell:

Done! Re-running the Bash cell will now install the package in the Python runtime's filesystem, making the import in the Python cell work:

What if I have other runtimes present?

If you already have non-Bash runtimes within your notebook (and therefore non-Bash runtimes present), Nextjournal takes a guess and makes the Bash cell you add automatically share the most recently introduced runtime, assuming you want to install packages for it. This happens below for this Python runtime:

That allows you to use anything you install in that Bash code cell from the shared runtime's code cells.

If you'd like to connect your Bash code cell to another runtime, use the Change runtime... option from the Command Bar:

Independent (or not) Bash runtimes

Bash cells are special; they are the only ones that can connect to other language runtimes. To see immediately whether a Bash code cell has its own, independent runtime, or whether it shares another code cell's runtime, take a look at the bottom right of the cell: here, it's not “Bash” anymore, but “Bash in Python”, meaning it shares an existing Python's runtime.

Prevent having to re-install packages

The file system state of a runtime is transient by default. This means that, whenever the runtime shuts down or is reset (either initiated by you, or automatically after 20 minutes of idle time), all installed packages are lost, and have to be re-installed. To learn how to prevent this, read our guide on saving and reusing your environment.

Installing packages for different languages

This was a short introduction to installing packages in Nextjournal. For more details on installing and configuring packages in the different languages we support, see our detailed guide!