Skip to content

Instantly share code, notes, and snippets.

@danwild
Created November 4, 2016 00:53
Show Gist options
  • Save danwild/d7225afe4b7dbdeeb87982f0e71012f3 to your computer and use it in GitHub Desktop.
Save danwild/d7225afe4b7dbdeeb87982f0e71012f3 to your computer and use it in GitHub Desktop.
Install netCDF4 in Ubuntu
#!/bin/bash
# Script to install hdf5 and netCDF4 libraries on a Linux Ubuntu system
# After: https://code.google.com/p/netcdf4-python/wiki/UbuntuInstall
# And http://unidata.github.io/netcdf4-python/
# You can check for newer version of the programs on
# ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-4/
# and other sources
BASHRC="~/.bashrc"
# Install zlib
v=1.2.8
wget ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-4/zlib-${v}.tar.gz
tar -xf zlib-${v}.tar.gz && cd zlib-${v}
./configure --prefix=/usr/local
#sudo make check install
sudo make install
cd ..
# Install HDF5
v=1.8.13
wget ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-4/hdf5-${v}.tar.gz
tar -xf hdf5-${v}.tar.gz && cd hdf5-${v}
prefix="/usr/local/hdf5-$v"
if [ $HDF5_DIR != $prefix ]; then
echo "Add HDF5_DIR=$prefix to .bashrc"
echo "" >> $BASHRC
echo "# HDF5 libraries for python" >> $BASHRC
echo export HDF5_DIR=$prefix >> $BASHRC
fi
./configure --enable-shared --enable-hl --prefix=$HDF5_DIR
make -j 2 # 2 for number of procs to be used
sudo make install
cd ..
# Install Netcdf
v=4.1.3
wget http://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-${v}.tar.gz
tar -xf netcdf-${v}.tar.gz && cd netcdf-${v}
prefix="/usr/local/"
if [ $NETCDF4_DIR != $prefix ]; then
echo "Add NETCDF4_DIR=$prefix to .bashrc"
echo "" >> $BASHRC
echo "# NETCDF4 libraries for python" >> $BASHRC
echo export NETCDF4_DIR=$prefix >> $BASHRC
fi
CPPFLAGS=-I$HDF5_DIR/include LDFLAGS=-L$HDF5_DIR/lib ./configure --enable-netcdf-4 --enable-shared --enable-dap --prefix=$NETCDF4_DIR
# make check
make
sudo make install
cd ..
# install python's netCDF4
sudo -E pip install netCDF4 --upgrade
@mgdangin
Copy link

Hello,
Is there a way to uninstall this?

@LoryPack
Copy link

LoryPack commented Jul 6, 2021

Be careful when running this script as installing a new version of zlib on top of a previous one can break library dependencies (it happened to me). Maybe it would be better to first check whether zlib is already available

@AaronRodriguezJimenez
Copy link

HELP!! After running the script I get errors of installation. I delete the generated data and then reboot, then Ubuntu cannot longer initialise, does anybody knows how can I fix this problem? I can access to GRUB, but Ubuntu gets stucked and don't initialise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment