Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving .ghc and .cabal to a different user

Tags:

haskell

ghc

cabal

How can I move the GHC and cabal installed packages to a different user? I've copied the directories but I'm getting error messages like:

ConfigParser.hs:15:8:
    Could not find module `Data.ByteString.Char8'
    There are files missing in the `bytestring-0.10.2.0' package,
    try running 'ghc-pkg check'.
    Use -v to see a list of the files searched for.

ghc-pkg check shows that any file for any package is missing. How can I resolve this?

Note: This question intentionally does not show research effort, because it was answered Q&A-style.

like image 699
Uli Köhler Avatar asked Feb 03 '26 14:02

Uli Köhler


1 Answers

First, you obviously need to copy .ghc and .cabal. These contain the binary files and configurations.

For simplicity, we will assume moving from user foo to user bar. Note that moving between architectures is not possible, as the binaries produced by GHC are not platform-independent.

After copying the aforementioned directories, there are paths like /home/foo remaining in different locations. We will use sed to replace those (run this as bar):

sed -i -e "s/foo/bar/g" ~/.cabal/config
sed -i -e "s/foo/bar/g" ~/.ghc/*-*/package.conf.d/*.conf

However, the file ~/.ghc/*-*/package.conf.d/package.cache still contains file references containing the username. We can't simply use sed to replace, however, because it's a binary file and it might destroy the package cache.

You can use ghc-pkg recache --user to re-cache all packages.

After performing these steps, you should be able to use the cabal packages as expected.

like image 120
Uli Köhler Avatar answered Feb 05 '26 09:02

Uli Köhler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!