Datanaut Environment
Using Bash cells to install packages and modify the filesystem in a Nextjournal runtime
1. Standalone Bash Runtimes
Each Nextjournal code cell runs in a runtime, and each runtime has an environment, which is a Docker container with its own filesystem. The first time we insert a Bash cell it will get a new Bash runtime using the default 'Minimal Bash' environment.
The underlying Linux distribution is Ubuntu 18.04 LTS, so we can install packages with apt-get
; however, the stock Nextjournal environments do not have package lists stored, so an apt-get update
is required first.
apt-get update > /dev/null
apt-get install -y fortune cowsay
We can also compile and install from source after getting the right tools.
apt-get install -y git gcc make libcurl4-openssl-dev
git clone --recursive git@github.com:alexisylchan/introdl.git
2. Bash in Other Languages
It's all well and good to have a standalone Bash runtime, but what if we also need to install packages in R or Julia, where it's more convenient to use the interpreter? While it's possible to accomplish this with a chain of multiple exported environments, the better way is to put a Bash cell into another language's runtime.
This can be accomplished using Change Runtime under a code cell's ··· menu. Here we can create a new runtime based on another environment, or put the cell into an existing environment.
Here we have a Bash cell in our R runtime. We'll install libhdf5-dev and its dependencies...
apt-get update > /dev/null apt-get install -y --no-install-recommends libhdf5-dev
...and with those we can build and install h5 in R.
install.packages("h5")