How do I run `stack upgrade` non-interactively?

I’m running automatic builds for a tool written in Haskell, but I got the following:

Current Stack version: 2.7.5, available download version: 2.9.1
Newer version detected, downloading
Querying for archive location for platform: linux-x86_64-static
Downloading from: https://github.com/commercialhaskell/stack/releases/download/v2.9.1/stack-2.9.1-linux-x86_64.tar.gz
Download complete, testing executable
Version 2.9.1, Git revision 409d56031b4240221d656db09b2ba476fe6bb5b1 x86_64 hpack-0.35.0

Warning: Installation path /build/.local/bin not found on the PATH environment variable.
New stack executable available at /build/.local/bin/stack
Also copying stack executable to /usr/bin/stack
Permission error when trying to copy: /usr/bin: copyFile:atomicCopyFileContents:withReplacementFile:openBinaryTempFile: permission denied (Permission denied)
Should I try to perform the file copy using sudo? This may fail
Try using sudo? (y/n)

I’m running stack upgrade and it tries to ask interactively while nobody is there. It eventually timed out.

I’ve read the docs at Install/upgrade - The Haskell Tool Stack but it doesn’t seem to tell me what to do with it. (I don’t want it to call sudo because it will fail. I can’t do anything interactively in the build environment.)

You can also use ghcup to manage stack these days. One of the primary design goals of ghcup (the CLI interface) is non-interactivity:

curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | BOOTSTRAP_HASKELL_NONINTERACTIVE=1 BOOTSTRAP_HASKELL_MINIMAL=1 sh
source ~/.ghcup/env
ghcup install stack latest

To upgrade, you just run ghcup install stack latest again.

2 Likes

Thanks, that worked!