3

I'm trying to install an R package called "ncdf4". I've tried installing it in the "packages" section in the R-studio interface, but have also tried entering install.packages("ncdf4") into the console.

This is the output I get in both instances:

Installing package into ‘/home/user/R/x86_64-pc-linux-gnu-library/3.6’
(as ‘lib’ is unspecified)
trying URL 'https://cloud.r-project.org/src/contrib/ncdf4_1.17.tar.gz'
Content type 'application/x-gzip' length 124458 bytes (121 KB)
==================================================
downloaded 121 KB

* installing *source* package ‘ncdf4’ ...
** package ‘ncdf4’ successfully unpacked and MD5 sums checked
** using staged installation
configure.ac: starting
checking for nc-config... no
-----------------------------------------------------------------------------------
Error, nc-config not found or not executable.  This is a script that comes with the
netcdf library, version 4.1-beta2 or later, and must be present for configuration
to succeed.

If you installed the netcdf library (and nc-config) in a standard location, nc-config
should be found automatically.  Otherwise, you can specify the full path and name of
the nc-config script by passing the --with-nc-config=/full/path/nc-config argument
flag to the configure script.  For example:

./configure --with-nc-config=/sw/dist/netcdf4/bin/nc-config

Special note for R users:
-------------------------
To pass the configure flag to R, use something like this:

R CMD INSTALL --configure-args="--with-nc-config=/home/joe/bin/nc-config" ncdf4

where you should replace /home/joe/bin etc. with the location where you have
installed the nc-config script that came with the netcdf 4 distribution.
-----------------------------------------------------------------------------------
ERROR: configuration failed for package ‘ncdf4’
* removing ‘/home/user/R/x86_64-pc-linux-gnu-library/3.6/ncdf4’
Warning in install.packages :
  installation of package ‘ncdf4’ had non-zero exit status

The downloaded source packages are in
    ‘/tmp/RtmpXcbO2y/downloaded_packages’

Is anybody able to decipher what went wrong from the code that I've provided? Thanks.

AlexLee
  • 429
  • 4
  • 11
  • 1
    The error message there is telling you that you need `netcdf` installed to install that R package. How to install `netcdf` on your Linux box is going to be distro specific. What are you running? – duckmayr Jan 07 '20 at 12:41
  • Duckmayr, I'm using a Chromebook with Crostini Linux. – AlexLee Jan 08 '20 at 17:35
  • tall.packages('netcdf4') Installing package into ‘C:/Users************************/R/win-library/4.1’ (as ‘lib’ is unspecified) --- Please select a CRAN mirror for use in this session --- Warning message: package ‘netcdf4’ is not available for this version of R A version of this package for your version of R might be available elsewhere, see the ideas at https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages > and it is the latest R 4.1.2 – Marian Jan 28 '22 at 01:46

5 Answers5

6

I am using Ubuntu 20.4 and ran into the same problem.

Step 1: in the terminal

sudo apt-get update -y

Step 2: in the terminal

sudo apt-get install -y libnetcdf-dev

Step 3: in RStudio

install.packages("ncdf4")

After that ncdf4 was installed successfully.

Reference: https://zoomadmin.com/HowToInstall/UbuntuPackage/libnetcdf-dev

Scarabee
  • 5,437
  • 5
  • 29
  • 55
Fadi
  • 76
  • 1
  • 2
  • 1
    Reference are ok. But include every step required in the solution and don't depends on external urls that may not be valid or accessible in the future. – Gi1ber7 Oct 14 '20 at 20:25
  • `sudo apt-get update --fix-missing` worked for me in Step 1 – Manuel F Mar 16 '21 at 23:26
3

I finally managed to install ncdf4.

I read a similar problem here: https://r.789695.n4.nabble.com/Problem-installing-ncdf-library-td4646986.html

I installed all the libnetcdf packages in the linux terminal by typing: sudo apt install libnetcdf-*

AlexLee
  • 429
  • 4
  • 11
1

If you are running Ubuntu18.04 or a derived version of it, you can look for the library netcdf4.1 by doing:

sudo apt-cache search libnetcdf

In my session (Linux Mint), I get:

libnetcdf-c++4 - legacy NetCDF C++ interface
libnetcdf-c++4-1 - C++ interface for scientific data access to large binary data
libnetcdf-c++4-dbg - debugging symbols for NetCDF C++
libnetcdf-c++4-dev - creation, access, and sharing of scientific data in C++
libnetcdf-c++4-doc - NetCDF C++ API documentation
libnetcdf-cxx-legacy-dbg - debugging symbols for legacy NetCDF C++ interface
libnetcdf-cxx-legacy-dev - legacy NetCDF C++ interface - development files
libnetcdf-dev - creation, access, and sharing of scientific data
libnetcdf13 - Interface for scientific data access to large binary data
libnetcdff-dbg - debugging symbols for NetCDF Fortran
libnetcdff-dev - creation, access, and sharing of scientific data in Fortran
libnetcdff-doc - NetCDF Fortran documentation
libnetcdff6 - Fortran interface for scientific data access to large binary data

So, installing the libnetcdf-c++4-1 should solve your issue:

sudo apt-get update
sudo apt-get install libnetcdf-c++4-1

Does it answer your question ?

dc37
  • 15,840
  • 4
  • 15
  • 32
1

For Arch Linux users, you probably haven't installed netcdf. You can use pacman to install netcdf

sudo pacman -S netcdf
0

just install netcdf via apt

apt-get install libnetcdf-dev

it worked for me (ubuntu 20.04 and R 4)

Walt Santos
  • 1
  • 1
  • 1