# Error building MPI---ERROR: LoadError: libmpi could not be found

**URL:** <https://discourse.julialang.org/t/error-building-mpi-error-loaderror-libmpi-could-not-be-found/65016>\
**Category:** General Usage\
**Tags:** package, mpi\
**Created:** [July 21, 2021, 5:21am UTC](https://discourse.julialang.org/t/error-building-mpi-error-loaderror-libmpi-could-not-be-found/65016 "2021-07-21T05:21:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![QuanlingDeng](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/quanlingdeng/32/27360_2.png) [@QuanlingDeng](https://discourse.julialang.org/u/QuanlingDeng)\
**Post date:** [July 21, 2021, 5:21am UTC](https://discourse.julialang.org/t/error-building-mpi-error-loaderror-libmpi-could-not-be-found/65016/1 "2021-07-21T05:21:11Z")

</div>

I was trying to build MPI and had the following error (after several searches/tries, see below)

**(@v1.6) pkg\>** build MPI

**Building** MPI → `~/.julia/scratchspaces/44cfe95a-1eb2-52ea-b672-e2afdf69b78f/00488c6fcaf828685c2bc5139bf0afff8c15c982/build.log`

**ERROR:** Error building `MPI`:

[ Info: using system MPI

ERROR: LoadError: libmpi could not be found

Stacktrace:

[1] error(s::String)

@ Base ./error.jl:33

[2] top-level scope

@ ~/.julia/packages/MPI/90ZrE/deps/build.jl:76

[3] include(fname::String)

@ Base.MainInclude ./client.jl:444

[4] top-level scope

@ none:5

in expression starting at /Users/quanlingdeng/.julia/packages/MPI/90ZrE/deps/build.jl:64

Some background info:

1. my julia version is 1.6.1
2. my mpi version is (Open MPI) 4.1.1
3. my openmpi location is /usr/local/Cellar/open-mpi/4.1.1\_2

What I tried

1. specified the JULIA\_MPI\_PATH by following  
[You appear to have run julia under a different `mpiexec` than the one used by MPI.jl](https://discourse.julialang.org/t/you-appear-to-have-run-julia-under-a-different-mpiexec-than-the-one-used-by-mpi-jl/51836)  
or  
[Error in bulid MPI](https://discourse.julialang.org/t/error-in-bulid-mpi/43948)
2. tried

```julia
julia --project -e 'ENV["JULIA_MPI_BINARY"]="system"; using Pkg; Pkg.build("MPI"; verbose=true)'

```

All these led to same error: “libmpi could not be found”

A similar issue appears here  
(~/t/error-building-mpi-libmpi-could-not-be-found/63785  
replace ~ by the webpage domain. I can only post two links as being a new user;-) )

I was wondering if anyone could help with building MPI in Julia? Thanks in advance.

---

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [July 21, 2021, 6:05am UTC](https://discourse.julialang.org/t/error-building-mpi-error-loaderror-libmpi-could-not-be-found/65016/2 "2021-07-21T06:05:48Z")

</div>

Take a look at the other environmental variables listed here:  
[https://juliaparallel.github.io/MPI.jl/latest/configuration/#environment\_variables](https://juliaparallel.github.io/MPI.jl/latest/configuration/#environment_variables)

---

<div class="post-metadata">

**Author:** ![QuanlingDeng](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/quanlingdeng/32/27360_2.png) [@QuanlingDeng](https://discourse.julialang.org/u/QuanlingDeng)\
**Post date:** [July 22, 2021, 1:13am UTC](https://discourse.julialang.org/t/error-building-mpi-error-loaderror-libmpi-could-not-be-found/65016/3 "2021-07-22T01:13:56Z")

</div>

> [@mkitti](#):
>
> variables

Thanks a lot!  
I have now figured it out and it worked.  
I did not change any of these other environmental variables but did the following

1. go to a terminal
2. type emacs ~/.julia/prefs/MPI.toml
3. set path = “/usr/local/Cellar/open-mpi/4.1.1\_2”

It seems that the way of setting the path is different from the ways in the two links in my original post which were in the files ~/.bash\_profile or ~/.profile

Maybe it’s Julia version thing

---

<div class="post-metadata">

**Author:** ![christmas\_jones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christmas_jones/32/29540_2.png) [@christmas\_jones](https://discourse.julialang.org/u/christmas_jones)\
**Post date:** [July 20, 2022, 5:54pm UTC](https://discourse.julialang.org/t/error-building-mpi-error-loaderror-libmpi-could-not-be-found/65016/4 "2022-07-20T17:54:40Z")

</div>

Thanks for this, this was bugging me for ages (on Mac M1, julia 1.8). I found I also had to set the library path for it to not throw the error about libmpi. For me, I had MPI installed via homebrew, and the following steps worked (in case anyone else had similar issues):

```julia
export JULIA_MPI_PATH=/opt/homebrew/Cellar/open-mpi/4.1.4
export JULIA_MPI_LIBRARY=/opt/homebrew/Cellar/open-mpi/4.1.4/lib/libmpi
julia -e 'ENV["JULIA_MPI_BINARY"]="system"; using Pkg; Pkg.build("MPI"; verbose=true)'

```

This resulted in the MPI.toml file (you can find in .julia/prefs) being (automatically) set up as:

```julia
library = "/opt/homebrew/Cellar/open-mpi/4.1.4/lib/libmpi"
binary = "system"
path = "/opt/homebrew/Cellar/open-mpi/4.1.4"

```

and I was able to run mpiexec/mpirun as expected with julia.

Also note, if I did the above, but with e.g. “/opt/homebrew/lib” it did not work, even though there are libmpi.dylib files there. The issue, I believe, is these are aliases, and if you do ‘show original’ it takes you to the path I used above.
