# How to compile R/igraph from source, with all features enabled?

**URL:** <https://igraph.discourse.group/t/how-to-compile-r-igraph-from-source-with-all-features-enabled/1190>\
**Category:** Development\
**Tags:** R\
**Created:** [19 April 2022 12:43 UTC](https://igraph.discourse.group/t/how-to-compile-r-igraph-from-source-with-all-features-enabled/1190 "2022-04-19T12:43:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [19 April 2022 12:43 UTC](https://igraph.discourse.group/t/how-to-compile-r-igraph-from-source-with-all-features-enabled/1190/1 "2022-04-19T12:43:36Z")

</div>

**NOTICE:** This thread is written for igraph developers. If you are a user trying to compile R/igraph on Windows or macOS: do you really need to do it? Consider using (possibly older) binary releases from CRAN instead.

* * *

In this thread, let’s write up detailed instructions on how to compile R/igraph from sources on all supported platforms: Windows, macOS (Intel/ARM), Linux.

This will be useful because it takes some time until CRAN generates all binaries. For 1.3.0, it took over a week and in the meantime, people keep asking about how to compile.

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [19 April 2022 12:46 UTC](https://igraph.discourse.group/t/how-to-compile-r-igraph-from-source-with-all-features-enabled/1190/2 "2022-04-19T12:46:13Z")

</div>

## General notes

Make sure that all requirements are present:

- C, C++ and Fortran compilers
- GLPK and libxml2 libraries, including development headers
- Ensure that R can find these

Then `install.packages("igraph")` will work.

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [19 April 2022 12:48 UTC](https://igraph.discourse.group/t/how-to-compile-r-igraph-from-source-with-all-features-enabled/1190/3 "2022-04-19T12:48:40Z")

</div>

## Linux

Install the above requirements using the facilities of your Linux distribution.

### Debian-based distros

```auto
sudo apt install build-essential gfortran libxml2-dev libglpk-dev

```

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [19 April 2022 12:53 UTC](https://igraph.discourse.group/t/how-to-compile-r-igraph-from-source-with-all-features-enabled/1190/4 "2022-04-19T12:53:54Z")

</div>

## Windows

[Install RTools](https://cran.r-project.org/bin/windows/Rtools/). Be sure to follow the installation instructions precisely, including setting the `PATH`. The below instructions assume that you are using RTools 4.0 or later.

Open an RTools terminal and install the required dependencies using `pacman`. Instructions for using `pacman` are [here](https://github.com/r-windows/docs/blob/master/rtools40.md#example-installing-a-library-with-pacman).

First update the package index:

```auto
pacman -Sy

```

Install the requirements:

```auto
pacman -Sy mingw-w64-{i686,x86_64}-glpk mingw-w64-{i686,x86_64}-libxml2 mingw-w64-{i686,x86_64}-gmp

```

---

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)\
**Post date:** [19 April 2022 13:00 UTC](https://igraph.discourse.group/t/how-to-compile-r-igraph-from-source-with-all-features-enabled/1190/5 "2022-04-19T13:00:00Z")

</div>

## macOS

Choose a section depending on whether you want to use developer tools from the official RTools, MacPorts, or Homebrew.

### RTools

**TODO**

Get the developer tools from:

- [Tools - R for Mac OS X - developer's page - GNU Fortan for Xcode](https://mac.r-project.org/tools/)

Download the dependencies (GLPK and libxml2 libraries) from:

- [Optional Libraries, Frameworks and Applications for macOS](https://mac.r-project.org/libs-4/) (Intel)
- [Optional Libraries, Frameworks and Applications for macOS (arm64)](https://mac.r-project.org/libs-arm64/) (ARM)

### MacPorts

**Warning:** If you are using the official R distribution, using other compilers than what come with RTools is not officially supported by the R maintainers.

Install compilers and libraries:

```auto
sudo port install clang-14 gcc11 libxml2 glpk

```

We need to ensure that R will use the compilers and libraries from MacPorts. Place the following in `~/.R/Makevars`:

```auto
CC = /opt/local/bin/clang-mp-14
CXX = /opt/local/bin/clang++-mp-14
FC = /opt/local/bin/gfortran-mp-11
F77 = /opt/local/bin/gfortran-mp-11
FLIBS = -L/opt/local/lib/gcc11 -lgfortran -lquadmath -lm
CPPFLAGS=-I/opt/local/include
LDFLAGS=-L/opt/local/lib

```

If you install different versions of compilers than what is shown above, the contents of `Makevars` will need to be updated accordingly.

### Homebrew

**Warning:** If you are using the official R distribution, using other compilers than what come with RTools is not officially supported by the R maintainers.

**TODO**
