Skip to content

Installing FEniCS on macOS and Linux

FEniCS can be installed on macOS and Linux in two simple ways:

  1. Using Anaconda (Conda Environment)
  2. Using Docker (Containerized Environment)

Both methods are officially supported and work reliably for most simulation workflows.

The Docker approach is the recommended installation process for all new members, as it provides a fully pre-configured, isolated setup ensuring consistency across systems. However, the Anaconda approach is still a great choice for those who prefer a native installation.

Option 1 — Installing FEniCS using Docker (macOS & Linux)

If you prefer a clean, isolated environment or don’t want to install dependencies manually, Docker is the easiest way to run FEniCS. This is also the recommended method at Avkalan Labs, since it ensures consistency across all systems.

Before starting, make sure Docker is installed on your system. You can follow this tutorial for installation: 🔗 Installing Docker

Step 1 — Pull the FEniCS Docker Image

Open your terminal and run:

bash
docker pull iitrabhi/fenics_notebook

This downloads a pre-configured image that includes:

  • Ubuntu (base system)
  • FEniCS pre-installed
  • Jupyter Notebook environment
  • Python scientific libraries (numpy, meshio, matplotlib, etc.)

Step 2 — Run FEniCS in a Container

Once the image is downloaded, start a container with this command:

bash
docker run -p 8888:8888 -v host_system_path:/root/ -w /root/ iitrabhi/fenics_notebook

Let’s understand what each part does:

  • -p 8888:8888 → maps Jupyter’s port to your local system
  • -v host_system_path:/root/ → links your local folder (where your code is) to the container
  • -w /root/ → sets the working directory inside the container

You’ll need to replace host_system_path with your actual code folder’s path.

For example:

bash
docker run -p 8888:8888 -v /Users/username/Codes:/root/ -w /root/ iitrabhi/fenics_notebook

On Linux, paths look like /home/username/fenics_projects, on macOS, /Users/username/fenics_projects.

Tip: Avoid using spaces in folder names — use underscores instead (e.g., fenics_projects).

Step 3 — Access Jupyter Notebook

After running the container, Docker will print a message with a URL like:

http://127.0.0.1:8888/?token=abcdef...

Copy that URL and open it in your browser. You’ll see the Jupyter Notebook interface, ready to run FEniCS code inside the container.

Option 2 — Installing FEniCS using Anaconda (Linux & macOS)

If you already have Anaconda or Miniconda installed, you can set up FEniCS in a new environment with just a few commands.

Step 1 — Create a new FEniCS environment

Open your terminal and run:

bash
conda create -n fenicsproject -c conda-forge fenics

This will create a new environment named fenicsproject with all FEniCS dependencies preinstalled.

Step 2 — Activate the environment

Once the installation is done, activate it using:

bash
source activate fenicsproject

Now you can run Python and import FEniCS modules like dolfin, ufl, and mshr.

Step 3 — Test your installation

Run Python inside the environment and test:

bash
python3 -c "import dolfin; print(dolfin.__version__)"

If it prints a version number (e.g., 2019.1.0), you’re good to go.

Tip: You can deactivate the environment anytime using:

bash
conda deactivate

Notes

  • Both Conda and Docker methods work well — choose Docker for consistency and isolation, or Conda for native integration.
  • Using Docker ensures everyone in your team works in the same environment — ideal for collaborative projects.
  • If you’re using Docker frequently, you can create a small shell script to launch it quickly with your preferred folder path.
  • The Docker-based guide is also available here: 🔗 Running FEniCS in Docker

Summary

  • For Conda users:

    bash
    conda create -n fenicsproject -c conda-forge fenics  
    source activate fenicsproject
  • For Docker users:

    bash
    docker pull iitrabhi/fenics_notebook  
    docker run -p 8888:8888 -v /Users/username/Codes:/root/ -w /root/ iitrabhi/fenics_notebook

Once either setup is ready, you can start building and running your FEniCS simulations right away — on both macOS and Linux.