How do I install Haskell Stack locally?

2019-04-09 07:29发布

I am working on my school server and I need to install Haskell's stack. In the README file and on the website I could not find how to install locally. What can I do if I am not a sudo user?

2条回答
▲ chillily
2楼-- · 2019-04-09 07:42

The Haskell stack is successfully installed using the instructions in Documentation here.

As the case with "sudo user", the command sudo grants a user with super user privileges by flipping the mode bit. The details regarding the mechanism can be found here.

The problem in your case might be the reason that in "School Networks", users are restricted to use sudo for security purposes and hence, either the administrators must grant your account privileges or they must install the Haskell stack themselves. If this is a part of an assignment, adminstrators should have no problem doing so and you must inform administrators regarding this. Thereafter, you must be able to use it comfortably.

If the above steps are not possible, I would suggest you to try out Haskell stack in your personalized account on a device. You may even try out Cloud services like Cloud9, Nitrous and others. An unlikely reason might be that you are not using the Haskell stack properly.

Note: I have used the Haskell stack for some time, hence, I can conclude that it works.

查看更多
等我变得足够好
3楼-- · 2019-04-09 07:50

You don't need superuser privileges to install stack; you can as well install it in your own home directory. All you need for this to work is a Linux system with GMP installed (which GHC depends on at a very fundamental level). If GMP is not installed – the admins really shouldn't have any concerns installing that.

#!/bin/bash

# Stack installation script, adapted from:
# https://github.com/yantonov/install-ghc/blob/af0b968b9e8423efb152ccec4224821e29317710/ubuntu/install-ghc-ubuntu.md

DOWNLOADS_DIR=$HOME/Downloads
STACK_INSTALL_DIR="$HOME/Development/bin"
STACK_VERSION="1.1.2"  
STACK_ARCHITECTURE="x86_64"  
STACK_PLATFORM="linux"  

# Check that libgmp is installed. This is the main critical system-level
# dependency of the Haskell environment that may not be present.

function check_lib()
{
    echo "int main(){}" | gcc -o /dev/null -lgmp -x c -
    return $?
}

GMP_OK=false
if (ldconfig -p | grep -q "libgmp.so.10"); then
    GMP_VERSION_POSTFIX=""
    if (check_lib -lgmp); then GMP_OK=true; fi
elif (ldconfig -p | grep -q "libgmpxx.so.4"); then
    GMP_VERSION_POSTFIX="-gmp4"
    if (check_lib -lgmp); then GMP_OK=true; fi
fi


if [ $GMP_OK = false ]; then
    echo >&2 "Haskell requires the GNU multi-precision library (with headers)"
    echo >&2 "in version 4 or 10, but neither can be found. Try"
    echo >&2
    echo >&2 "$ sudo apt-get install libgmp-dev"
    echo >&2
    exit 1
fi

STACK_DIST_FILENAME="stack-$STACK_VERSION-$STACK_PLATFORM-$STACK_ARCHITECTURE.tar.gz"  
STACK_DIST_UNZIPPED_DIR="stack-$STACK_VERSION-$STACK_PLATFORM-$STACK_ARCHITECTURE"
STACK_DIST_URL="https://www.stackage.org/stack/$STACK_PLATFORM-$STACK_ARCHITECTURE"
STACK_TARGET_DIR="stack-$STACK_VERSION"

cd $DOWNLOADS_DIR

curl -L -o $STACK_DIST_FILENAME $STACK_DIST_URL  
tar xvfz $STACK_DIST_FILENAME

# 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

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

cd $STACK_INSTALL_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
stack setup
查看更多
登录 后发表回答