Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
How to install latest GHC from source + latest stack + cabal + cabal-install on ubuntu

How to install latest GHC from source + latest stack + cabal + cabal-install on ubuntu

for your convinience these instuction is available as:
gist
git repo

preferred way install stack than install ghc

stack (package manager and build tool, preferrered way to manage dependencies)

# settings
DOWNLOADS_DIR=$HOME/Downloads

STACK_ARCHITECTURE="x86_64"  
STACK_PLATFORM="linux"  
STACK_DIST_URL="https://www.stackage.org/stack/$STACK_PLATFORM-$STACK_ARCHITECTURE"
STACK_INSTALL_DIR="$HOME/Development/bin"

cd $DOWNLOADS_DIR

curl -L -O $STACK_DIST_URL  

# in case if error like this: 
#curl: (77) error setting certificate verify locations: CAfile: 
# /etc/pki/tls/certs/ca-bundle.crt CApath: 
# ...
# create ~/.curlrc file
# and put this lines to it
# capath=/etc/ssl/certs/
# cacert=/etc/ssl/certs/ca-certificates.crt

STACK_DIST_FILENAME=`ls -1 | grep 'stack-.*\.tar\.gz'`
STACK_VERSION=`echo $STACK_DIST_FILENAME | sed -E 's/stack-([.0-9]+)-.*/\1/'`
STACK_TARGET_DIR="stack-$STACK_VERSION"
echo "stack $STACK_VERSION will be installed"  

tar xvf $STACK_DIST_FILENAME  
STACK_DIST_UNZIPPED_DIR=`ls -d -1 stack-*/`

# move to home development dir
rm -rf $STACK_INSTALL_DIR/$STACK_TARGET_DIR  
mkdir -p $STACK_INSTALL_DIR
mv $STACK_DIST_UNZIPPED_DIR $STACK_INSTALL_DIR/$STACK_TARGET_DIR

# sym link
rm -rvi stack  
ln -s `pwd`/$STACK_TARGET_DIR stack  

# add to PATH environment  
STACK_HOME=$HOME/Development/bin/stack  
PATH=$STACK_HOME:$PATH

# clean up
cd $DOWNLOADS_DIR
rm -rf stack-$STACK_VERSION*

install ghc using stack

# install ghc
stack setup
# run repl
stack ghci

OLD way (manual installation of ghc)

### ubuntu prerequisites

# Multiprecision arithmetic library developers tools, zlib  
sudo apt-get install libgmp-dev zlib1g-dev -y  
sudo -K

ghc

DOWNLOADS_DIR="$HOME/Downloads"

GHC_VERSION=`curl https://downloads.haskell.org/~ghc/ | grep -E '([.0-9]+)/' | sed -E 's/.*>([.0-9]+).*/\1/' | uniq | sort -r | head -n 1`
ARCHITECTURE="x86_64"  
# for 32 bit ARCHITECTURE="i386"  
PLATFORM="deb8-linux"  
GHC_DIST_FILENAME="ghc-$GHC_VERSION-$ARCHITECTURE-$PLATFORM.tar.xz"

### ghc installation

echo "GHC $GHC_VERSION will be installed"  

# get distr  
cd $DOWNLOADS_DIR
GHC_DIST_URL="https://www.haskell.org/ghc/dist/$GHC_VERSION/$GHC_DIST_FILENAME"
curl -L -O $GHC_DIST_URL  
tar xvfJ $GHC_DIST_FILENAME  
cd ghc-$GHC_VERSION  

# install to  
mkdir $HOME/Development/bin/ghc-$GHC_VERSION  
# or choose another path

./configure --prefix=$HOME/Development/bin/ghc-$GHC_VERSION  

make install

# symbol links  
cd $HOME/Development/bin
rm -f ghc
ln -s `pwd`/ghc-$GHC_VERSION ghc  

# add $HOME/Development/bin/ghc to $PATH  
# add this line to ~/.profile  
export GHC_HOME=$HOME/Development/bin/ghc  
export PATH=$GHC_HOME/bin:${PATH}

# to use updated path without log off
source ~/.profile

# remove temporary files  
cd $DOWNLOADS_DIR  
rm -rfv ghc-$GHC_VERSION*

cabal (package manager, old way to manage dependencies)

# remove old  
rm -rfv $HOME/.cabal
rm -rfv $HOME/.ghc

cabal library

CABAL_VERSION=`curl https://www.haskell.org/cabal/release/cabal-latest/ | grep -E 'Cabal-([.0-9]+\.[0-9]).*' | sed -E 's/.*>Cabal-([.0-9]+\.[0-9]).*/\1/' | head -n 1`      
CABAL_DIST_FILENAME="Cabal-$CABAL_VERSION.tar.gz"

echo "Cabal $CABAL_VERSION will be installed..."  

# clone dist  
cd $DOWNLOADS_DIR  
curl -O "https://www.haskell.org/cabal/release/cabal-$CABAL_VERSION/$CABAL_DIST_FILENAME"  

# extract   
tar xzvf $CABAL_DIST_FILENAME  
cd Cabal-$CABAL_VERSION  

# build
ghc --make Setup.hs
./Setup configure --user --enable-library-profiling
./Setup build
./Setup install

# Remove temporary files
cd $DOWNLOADS_DIR
rm -rfv Cabal-$CABAL_VERSION*

cabal-install

CABAL_INSTALL_VERSION=`curl https://www.haskell.org/cabal/release/cabal-install-latest/ | grep -E 'cabal-install-([.0-9]+\.[0-9]).*' | sed -E 's/.*>cabal-install-([.0-9]+\.[0-9]).*/\1/' | head -n 1`      
CABAL_INSTALL_DIST_FILENAME="cabal-install-$CABAL_INSTALL_VERSION.tar.gz"  

echo "cabal install $CABAL_INSTALL_VERSION will be installed..."  

# get distributive  
cd $DOWNLOADS_DIR  
curl -O "https://www.haskell.org/cabal/release/cabal-install-$CABAL_INSTALL_VERSION/$CABAL_INSTALL_DIST_FILENAME"  

# extract archive  
tar xzvf $CABAL_INSTALL_DIST_FILENAME  
cd cabal-install-$CABAL_INSTALL_VERSION  

# install  
./bootstrap.sh

# remove temporary files  
cd $DOWNLOADS_DIR  
rm -rfv cabal-install-$CABAL_INSTALL_VERSION*  

# add path to cabal to PATH environment
export CABAL_HOME=$HOME/.cabal
export PATH=$CABAL_HOME/bin:$PATH
@naphthalene

This comment has been minimized.

Show comment Hide comment
@naphthalene

naphthalene Dec 27, 2014

Thanks ^_^
edit: one small note: your instructions in the middle portion for the cabal-library are for version 1.20.0.2, not sure if intentional? I've forked and updated it with 1.20.0.3.

Thanks ^_^
edit: one small note: your instructions in the middle portion for the cabal-library are for version 1.20.0.2, not sure if intentional? I've forked and updated it with 1.20.0.3.

@yantonov

This comment has been minimized.

Show comment Hide comment
@yantonov

yantonov Dec 28, 2014

Thanks, fixed.

Owner

yantonov commented Dec 28, 2014

Thanks, fixed.

@selivanovm

This comment has been minimized.

Show comment Hide comment
@selivanovm

selivanovm Jan 23, 2015

Good stuff, thanks! The only thing - I needed to install zlib1g-dev to build cabal-install.

Good stuff, thanks! The only thing - I needed to install zlib1g-dev to build cabal-install.

@unthingable

This comment has been minimized.

Show comment Hide comment
@unthingable

unthingable Jan 28, 2015

Forgot the dot: CABAL_HOME=$HOME/.cabal

Forgot the dot: CABAL_HOME=$HOME/.cabal

@yantonov

This comment has been minimized.

Show comment Hide comment
@yantonov

yantonov Jan 28, 2015

@unthingable fixed, thanks!

Owner

yantonov commented Jan 28, 2015

@unthingable fixed, thanks!

@yantonov

This comment has been minimized.

Show comment Hide comment
@yantonov

yantonov Feb 8, 2015

@selivanovm thanks, fixed

Owner

yantonov commented Feb 8, 2015

@selivanovm thanks, fixed

@jprider63

This comment has been minimized.

Show comment Hide comment
@yantonov

This comment has been minimized.

Show comment Hide comment
@yantonov

yantonov Feb 17, 2015

@jprider63 added, thanks

Owner

yantonov commented Feb 17, 2015

@jprider63 added, thanks

@Tarrasch

This comment has been minimized.

Show comment Hide comment
@Tarrasch

Tarrasch Feb 20, 2015

@palmerba

This comment has been minimized.

Show comment Hide comment
@palmerba

palmerba May 20, 2015

Hey I'm having a problem with the ./bootstrap.sh it keeps telling me that it can't find haddock. Can anyone help me?

Hey I'm having a problem with the ./bootstrap.sh it keeps telling me that it can't find haddock. Can anyone help me?

@yantonov

This comment has been minimized.

Show comment Hide comment
@yantonov

yantonov May 21, 2015

@palmerba Check:
export GHC_HOME=$HOME/Development/bin/ghc
export PATH=$GHC_HOME/bin:${PATH}
I mean check than ghc and haddock are accessible using $PATH
At least ghc --version prints current version 7.10

Owner

yantonov commented May 21, 2015

@palmerba Check:
export GHC_HOME=$HOME/Development/bin/ghc
export PATH=$GHC_HOME/bin:${PATH}
I mean check than ghc and haddock are accessible using $PATH
At least ghc --version prints current version 7.10

@palmerba

This comment has been minimized.

Show comment Hide comment
@palmerba

palmerba May 21, 2015

So I got it to find haddock but now when I run it I get the error
src/Data/Binary.hs:1:1:
Could not find module 'Prelude'
Perhaps you haven't installed the "dyn" library for package 'base'?

So I got it to find haddock but now when I run it I get the error
src/Data/Binary.hs:1:1:
Could not find module 'Prelude'
Perhaps you haven't installed the "dyn" library for package 'base'?

@palmerba

This comment has been minimized.

Show comment Hide comment
@palmerba

palmerba May 21, 2015

Nevermind figured it out

Nevermind figured it out

@oguya

This comment has been minimized.

Show comment Hide comment
@oguya

oguya Aug 13, 2015

  • I keep getting the following error yet I've already installed ghc.

    joguya@localhost Cabal-1.22.4.0 $ ./Setup configure --user --prefix=/home/joguya/apps/cabal/1.22.4.0/
    Configuring Cabal-1.22.4.0...
    Setup: The program 'ghc' version >=6.4 is required but it could not be found.
    
  • installed ghc version

    joguya@localhost Cabal-1.22.4.0 $ ghc --version
    The Glorious Glasgow Haskell Compilation System, version 7.10.2
    
  • path to ghc

    joguya@localhost Cabal-1.22.4.0 $ which ghc
    ~/apps/ghc/7.10.2/bin/ghc
    joguya@localhost Cabal-1.22.4.0 $ echo $GHC_HOME 
    /home/joguya/apps/ghc/7.10.2/bin/ghc
    

oguya commented Aug 13, 2015

  • I keep getting the following error yet I've already installed ghc.

    joguya@localhost Cabal-1.22.4.0 $ ./Setup configure --user --prefix=/home/joguya/apps/cabal/1.22.4.0/
    Configuring Cabal-1.22.4.0...
    Setup: The program 'ghc' version >=6.4 is required but it could not be found.
    
  • installed ghc version

    joguya@localhost Cabal-1.22.4.0 $ ghc --version
    The Glorious Glasgow Haskell Compilation System, version 7.10.2
    
  • path to ghc

    joguya@localhost Cabal-1.22.4.0 $ which ghc
    ~/apps/ghc/7.10.2/bin/ghc
    joguya@localhost Cabal-1.22.4.0 $ echo $GHC_HOME 
    /home/joguya/apps/ghc/7.10.2/bin/ghc
    
@howaboutudance

This comment has been minimized.

Show comment Hide comment
@howaboutudance

howaboutudance Aug 16, 2015

on Debian I had to install the ghc-dynamic package via apt-get but otherwise smooth sailing. Otherwise running bootstrap.sh will give a error not finding Prelude. Thanks!

on Debian I had to install the ghc-dynamic package via apt-get but otherwise smooth sailing. Otherwise running bootstrap.sh will give a error not finding Prelude. Thanks!

@sportanova

This comment has been minimized.

Show comment Hide comment
@sportanova

sportanova Jan 18, 2016

Is there any advantage to not just using stack and creating executables directly from it?

Is there any advantage to not just using stack and creating executables directly from it?

@yantonov

This comment has been minimized.

Show comment Hide comment
@yantonov

yantonov Jan 19, 2016

@sportanova advantange...hmmm, no as i can judge, building ghc from source its just another way (thats why these instruction preserved)
of course you can install required version of ghc using stack setup

Owner

yantonov commented Jan 19, 2016

@sportanova advantange...hmmm, no as i can judge, building ghc from source its just another way (thats why these instruction preserved)
of course you can install required version of ghc using stack setup

@sportanova

This comment has been minimized.

Show comment Hide comment
@sportanova

sportanova Jan 19, 2016

@yantonov awesome - thanks!

@yantonov awesome - thanks!

@timo-a

This comment has been minimized.

Show comment Hide comment
@timo-a

timo-a Feb 9, 2017

@yantonov
$STACK_INSTALL_DIR/$STACK_TARGET_DIR is never created.

can you add mkdir -p $STACK_INSTALL_DIR/$STACK_TARGET_DIR ?

timo-a commented Feb 9, 2017

@yantonov
$STACK_INSTALL_DIR/$STACK_TARGET_DIR is never created.

can you add mkdir -p $STACK_INSTALL_DIR/$STACK_TARGET_DIR ?

@yantonov

This comment has been minimized.

Show comment Hide comment
@yantonov

yantonov Feb 12, 2017

@timo-a thanks, fixed

Owner

yantonov commented Feb 12, 2017

@timo-a thanks, fixed

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