Friday, January 23, 2009

Install JAGS and rjags in Fedora

JAGS was developed to help those non-Window users to be able to use BUGS. However, I found it is very hard to install JAGS and its R package-rjags. Here is my note on how to install JAGS and rjags in Fedora 10. The note here should work for all Linux systems.

Compile JAGS

1. Download JAGS source code from JAGS website into any folder. The file you are looking for should look like this JAGS-1.0.3.tar.gz. The version number which might be changed if JAGS is updated.

2. Extract the tar.gz file as: tar xfvz JAGS-1.0.3.tar.gz. This will create a JAGS-1.0.3 folder that contains JAGS files.

3. Go to JAGS folder as: cd JAGS-1.0.3.

4. Do the following to install JAGS:

sudo ./configure
sudo make
sudo make install

sudo is just a Linux command that force to execute command as the administrator

5. Type jags in the terminal console to see if JAGS is installed properly. Quite JAGS by typing exit.

Install rjags

1. In the terminal console, start R as:

sudo R

2. Install rjags. In the R console, type:

install.packages("rjags", configure.args="--with-jags-include=/usr/local/include/JAGS --with-jags-lib=/usr/local/lib/JAGS --with-jags-modules=/usr/local/lib/JAGS/modules")

In each --with above, there is an empty space to separate the code.

The trick here is that rjags will ask for JAGS HEADER file, libraries and modules. So if the above code does not work, search for them and specify the right PATH in the above code.

We have also written a package called R2jags that emulates what R2WinBUGS does. But it depends on rjags. So if you have successfully installed rjags, you might want to try R2jags. It has a powerful feature which is imported from rjags that you can pick up your previous saved MCMC and update it. I have a blog entry that discuss about this feature here.


Anonymous said...

Just FYI, on Debian

sudo apt-get install jags

gets you a pre-built version.

benjamin said...

On a mac (at time of this writing) I needed to add the flag:


Antonio Pedro said...

Does it work for Mac?

Many Thanks,


Yu-Sung Su said...

Mac OS is a member of linux family. Just make sure you have the latest X11. I believe this post works for Mac users.

Antonio Pedro said...

Many thanks,


Qiu said...

sudo apt-get install jags, won't work.

install lapack
apt-get install libblas-dev liblapack-dev

Unknown said...

Thank you, thank you, thank you.

Anonymous said...

Thanks a lot for this tutorial. Just a small comment: If I am not mistaken, you do not need to be root to do ./configure and make. What you need to do in Step 4 is

sudo make install

Anonymous said...

What you might want to do in Fedora prior to compiling JAGS is to type at the command line

sudo yum install lapack* blas* atlas*

Anonymous said...

If you want to install rjags on 64-bit Linux, be sure to check out RogBlog. There is a solution to a common problem that shows how to put the .so files into the correct directory.

Anonymous said...

If you have already installed JAGS on a 64-bit Linux system and now want to install rjags, an alternative to RogBlog's solution is to create symbolic links:

cd /usr/local/lib64
ln -s ../lib/* .

Note that the above assumes that the only files in /usr/local/lib are those pertaining to JAGS. If there are other files in this directory, you need to manually create symbolic links for


(this list pertains to JAGS 1.0.3). The approach involving symbolic links is less elegant than RogBlog's solution, but it avoids having to recompile JAGS in case JAGS is already installed.

Anonymous said...

What a great article, i got a lot of things from here. Thanks!


Unknown said...

So, I'm running these on MAC OS X v 10.5.8 and trying to install. I keep getting an error message because g++-4.2 is not found. Do you know if I have to install that compiler or if there's a way to get it to use the version of gcc that I currently have installed?

Thanks so much!!!!

Unknown said...

PS -- I was able to install it by updating my apple tools, and using their gcc compiler. Other distributions of gcc through the ports did not work!

Yu-Sung Su said...

To Elana,

You should also have the latest X11 to make the whole process works.

Unknown said...

To avoid being root, you can use the --prefix option when installing JAGS to specify where it's installed.

When doing that, though, I've had to use dyn.load to load in the dynamic libraries and to get rjags to work.

Has anyone found a way around this? Can you force rjags to recognize this location during the setup?

Kirsten and Chris said...

Hi, I don't know how old this post is but I've just submitted JAGS, coda, and rjags spec & srpm files to Fedora and hope to start maintaining these programs in Fedora. If anyone is interested, I currently have the RPMs for JAGS, coda, and rjags on my blog ...

After you install my JAGS rpms (both jags and jags-devel) all you need to do to install rjags is open up R and run install.packages("rjags") and everything should install fine.

I would also be interested in maintaing your R2jags program too.

Kirsten and Chris said...

I also wanted to add that there is now a i386 RPM for JAGS up on my blog as well.

Unknown said...

Hi there,
I just installed the rjags package on R 2.11.0 running on OS X 10.5.8 but when I tried to load the library I got the following error message:

Error : .onLoad failed in loadNamespace() for 'rjags', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared library '/Library/Frameworks/R.framework/Resources/library/rjags/libs/i386/':
dlopen(/Library/Frameworks/R.framework/Resources/library/rjags/libs/i386/, 10): Library not loaded: /usr/local/lib/libjags.1.dylib
Referenced from: /Library/Frameworks/R.framework/Resources/library/rjags/libs/i386/
Reason: image not found
Error: package/namespace load failed for 'rjags'

Does anybody have any idea how I could solve it?
Many thanks in advance,

Unknown said...

Thanks for your post and welcome to check: here

Unknown said...

I have opensuse.
I installed jags but I can not install rjags in R.
here is the log. Let me know what to do.

Selection: 63
trying URL ''
Content type 'application/x-gzip' length 62581 bytes (61 Kb)
opened URL
downloaded 61 Kb

* installing *source* package ârjagsâ ...
checking for prefix by checking for jags... /usr/bin/jags
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking how to run the C++ preprocessor... g++ -E
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking Console.h usability... no
checking Console.h presence... no
checking for Console.h... no
configure: error: in `/tmp/RtmpLc3krc/R.INSTALL65d940e4/rjags':
configure: error: "Problem with header file /usr/include/JAGS/Console.h "
See `config.log' for more details.
ERROR: configuration failed for package ârjagsâ
* removing â/home/users/farhadsh/R/x86_64-unknown-linux-gnu-library/2.12/rjagsâ

The downloaded packages are in
Warning message:
In install.packages("rjags") :
installation of package 'rjags' had non-zero exit status

Unknown said...
This comment has been removed by the author.
Josh said...

If going the easy way, don't forget to install the devel stuff as well. For example on OpenSUSE, also grab:

Unknown said...

Even setting the paths for lib, module and include on install.packages(), it's still not working. I'm using a CentOS7. Any ideas?


Imon Kearns said...

Sankey diagram is a very useful visualization to show the flow of data. Can you shed light which tools are best and easy to use to draw Sankey Diagram.