最佳答案
您不需要 super 用户权限来安装堆栈;您也可以将其安装在您自己的主目录中。要实现此功能,您所需要的只是一个带有 GMP 的 Linux 系统。已安装(GHC 在非常基础的层面上依赖于此)。如果未安装 GMP,管理员实际上不应该担心安装它。 (或者,按照these instructions在没有root权限的情况下安装GMP。)
#!/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"
mkdir -p ${STACK_INSTALL_DIR}
STACK_VERSION="2.1.3"
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
echo >&2 "or https://unix.stackexchange.com/questions/265239/how-to-install-a-custom-gmp-lib-for-just-one-user"
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
关于haskell - 如何在本地安装 Haskell Stack?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40206135/