Trouble with Installing Nloptr by Locally on Ubuntu

trouble with Installing nloptr by locally on Ubuntu

I figured it out by modifying configure and configure.ac.
All I did was fixing original NLOPT_URL to NLOPT_URL = "file:///home//usr//${NLOPT_TGZ}
Now it works like a charm!
Thanks for the help.

Cannot install nloptr (R 4.0.3, Ubuntu 20.04)

The latest (2.6.2) package of libnlopt-dev is broken in Ubuntu 20, for some reason it is compiled into a static library (.so shared object is missing)
I faced the similar problem a couple of days ago. The quick fix is to download NLOPT fron Github and compile it yourself
https://nlopt.readthedocs.io/en/latest/NLopt_Installation/
At least, it worked for me.

Installing nloptr on Linux

When you say [t]his command in turn looks for the following file online you only get half the story. Together with Jelmer, the maintainer of the actual nloptr package, I modified the package to do the following:

  • look for an install libnlopt library, and, if found, use it
  • if not found fall back to the old behaviour and download the library

So you could simply install nlopt via

 sudo apt-get install libnlopt-dev

(or the equivalent sudo dpkg -i /media/.... pointing to the file from a
USB drive etc pp) and then reinstall the nloptr package. It will just work. On my machine:

edd@max:~$ install.r nloptr         ## install.r is in littler
trying URL 'http://cran.rstudio.com/src/contrib/nloptr_1.0.4.tar.gz'
Content type 'application/x-gzip' length 353942 bytes (345 KB)
==================================================
downloaded 345 KB

* installing *source* package ‘nloptr’ ...
** package ‘nloptr’ successfully unpacked and MD5 sums checked
checking for g++... g++
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 whether we are using the GNU C++ compiler... (cached) yes
checking whether g++ accepts -g... (cached) yes
checking for pkg-config... yes
configure: Now testing for NLopt header file.
[...]
checking for nlopt.h... yes
configure: Suitable NLopt library found.
configure: creating ./config.status
config.status: creating src/Makevars
** libs
g++ -I/usr/share/R/include -DNDEBUG -fpic -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g -O3 -Wall -pipe -Wno-unused -pedantic -c dummy.cpp -o dummy.o
gcc -I/usr/share/R/include -DNDEBUG -fpic -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g -O3 -Wall -pipe -pedantic -std=gnu99 -c nloptr.c -o nloptr.o
g++ -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o nloptr.so dummy.o nloptr.o -lnlopt -lm -L/usr/lib/R/lib -lR
installing to /usr/local/lib/R/site-library/nloptr/libs
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (nloptr)

The downloaded source packages are in
‘/tmp/downloaded_packages’
edd@max:~$

Note how it compiled only two files from the actual R packages having found the nlopt installation.

Installing nloptr on Linux - fatal error: nlopt.h: No such file or directory

When Jelmer and I built this setup it just worked on my Ubuntu machines, and continues to do so--either with the download and build of nlopt, or via the system library.

As you are on Ubuntu, the easiest fix for you is probably to just install the system nlopt library, which the nloptr package will detect and use. So do

sudo apt-get install libnlopt-dev 

and then try installing nlopt again.

Similarly, you should be able to get lme4 as r-cran-lme4 from the appropriate PPAs by Michael Rutter as described in the README for Ubuntu at CRAN.

how to install nloptr on Linux

As discussed in comments above the issue here was a 'unconventional' (and hence not-working) 'installation' of the nlopt library: one cannot just untar it somewhere as the dynamic linker needs to know about it, update its cache etc.

So in short the recommended answer is to, where available as a suitable version, install the -dev package from the distro. Here the command is

sudo apt install libnlopt-dev

after which configure in the R package sees, and also gets to use it as the corresponding shared library itself gets installed from the libnlopt0 package. (And we answered a few times why the -dev package is always needed for building as opposed to merely running via the shared library package).

Problem installing nloptr in R 4.2.2 on Ubuntu 22.04

The comments by @jay.sf and myself give you the narrowest answer: you attempt to build from source, and compiling and linking requires the so-called -dev packages. So install r-base-dev.

Looking beyond this for a second though, you are on Ubuntu 22.04 and you have r-cran-nloptr inside the distribution too (albeit an older version). So sudo apt install r-cran-nloptr works as well.

And since this summer there is r2u which gives you (on Ubuntu 20.04 and Ubuntu 22.04) every CRAN package as an Ubuntu binary and is generally current. It is easy to set up and the command install.packages("ggpubr") would then reliably and quickly install the package and all its dependencies from binaries.

Trouble installing nloptr package on R 3.3.0

I had to reinstall R, using the R-CRAN installer and uninstalling the macports package.

It finally worked!

unable to install R package nloptr (R3.6.2 on Ubuntu 16.04) - C++ compiler issue

We have done a lot of work to make nloptr installation better. In essence, you have several choices:

  • if the system version of the nlopt library is present, use it -- that is the easiest so try installing it via sudo apt-get install libnlopt-dev and then reinstall

  • if it is not found, then a download of the source and build happens, and this seems to fail on your almost four year old Ubuntu system as it is hard to support all flavours --- but this works swimmingly on newer ones (I run Ubuntu too, but currently 19.10)

  • there are binaries for you as, see the Ubuntu packages page -- however these may not match your current R version which is mismatches to your distro R version

  • dependening on where you got R from (did you install a .deb?) you could use the Michael Rutter PPAs to get a current r-cran-nloptr

All this can also be discussed in detail on the r-sig-debian list for R on Debian and Ubuntu.

Edit: In response to the comment below:

  • To see what package apt knows about, do apt-cache policy r-cran-nloptr. Per the link I gave above we know Ubuntu has a r-cran-nloptr for your (very old) Xenial installation. However it will clash with the very new and current R you have running. Such as the costs of mixing and matching.

  • To access the Rutter PPAs and its over four thousand current binaries see the fourth paragraph at the top of the Ubuntu at CRAN README

Edit 2: I may have been too pessimistic. The Rutter PPA for the current R binaries has trusty, xenial and bionic. See https://launchpad.net/~marutter/+archive/ubuntu/c2d4u3.5



Related Topics



Leave a reply



Submit