"cabal install cabal-install" doesn't update cabal version in OSX - haskell

I'm a newbie to haskell and cabal, so I'm probably missing something simple.
I updated cabal-install:
sudo cabal install cabal-install
Password:
Resolving dependencies...
Configuring cabal-install-1.22.0.0...
Building cabal-install-1.22.0.0...
Installed cabal-install-1.22.0.0
Updating documentation index
However cabal --version says:
cabal-install version 1.18.0.5
using version 1.18.1.4 of the Cabal library
What happened to cabal-install 1.22.0.0?

There are two ways of making cabal install packages globally. Note that, as a result, cabal may require sudo.
This command will install <PACKAGE> globally:
$ cabal install <PACKAGE> --global
As a more general solution, edit the file ~/.cabal/config and set user-install to False. This will automatically set the --global flag so you can just write cabal install <PACKAGE> without any worry. Here's a snippet of my config file:
...
-- split-objs: False
-- executable-stripping: True
user-install: False
-- package-db:
-- flags:
...
You may also want to set root-cmd to sudo if it's not already, so that cabal will automatically prompt for the root password when it encounters a permission problem.
There's some more info online here.

I see that there's an updated cabal at ~/Library/Haskell/bin, so I could replace /usr/bin/cabal with a symbolic link to this copy or I could copy this binary to /usr/bin.
I'm still interested if there is a more elegant/canonical way to make sure the new cabal is what gets used by default.

TLDR: Try running hash -r
Bash has a PATH hashtable that maps commands to the location of binaries. You may still have an old version of cabal installed somewhere in your PATH (possibly in a sandbox). Since cabal is not a new command, the hashtable will keep serving up the old version. hash -r rebuilds the hashtable, so the shell will correctly find the new version (providing it appears earlier in your path than the old one).

Related

Cabal install reports package as installed, but Setup configure reports it as missing

I am using ghc-7.6.3 with cabal-install version 1.18.0.5 using version 1.18.1.3 of the Cabal library. My operating system is Debian Wheezy 7.5.
I have a fresh cabal install, and that I have removed the .ghc from my home directory.
After that I have changed the cabal config file and set:
remote-repo: stackage-nightly-2014-12-15:http://www.stackage.org/snapshot/nightly-2014-12-15
After that I did (following this documentation)
$ cabal update
$ cabal install alex happy yesod-bin
and the build complained that it cannot build package system-filepath-0.4.12.
So, I am trying to build package system-filepath-0.4.12 manually. After unpacking the archive, I cd-ed to the unpacked folder and entered:
$ ghc -o Setup Setup.hs
$ ./Setup configure
which gives:
Configuring system-filepath-0.4.12...
Setup: At least the following dependencies are missing:
text >=0.7.1
But
$ cabal install text
gives:
Resolving dependencies...
All the requested packages are already installed:
text-1.1.1.3
Use --reinstall if you want to reinstall anyway.
How is it possible that a package is reported as installed and missing at the same time?
Should I look for a more stable remote-repo configuration, is there something I can check that might fix the missing text package? Note that I am not using a sandbox.
EDIT
Thanks for pointing out that there are two package databases.
I have now tried both
$ cabal configure
$ cabal build
and
$ Setup configure --user
$ Setup build
Both give no error during configuration, but give the following error during the build phase:
Building system-filepath-0.4.12...
Preprocessing library system-filepath-0.4.12...
/usr/bin/ld: cannot find -lHStext-1.1.1.3-ghc7.8.3
collect2: error: ld returned 1 exit status
Try this instead
cd system-filepath--0.4.12
cabal configure
I am not sure why, but this works for me, whereas Setup.hs gave me the same error (truth be told, I always do it the cabal configure way, and am not sure if your way should also work).
There are (at least) two package databases: a global one available to all users, and a user-specific one. By default, Setup.hs looks in (and installs to) the global one, and cabal-install looks in (and installs to) the user-specific one. You can manually choose one or the other with --user and --global; so, you could fix this either by using
./Setup configure --user
or by
cabal install text --global
You can see the current state of the package databases with ghc-pkg, which will report information about both by default.

Darcs installed with cabal not registered as shell command

As a part of installing Ubuntu on my computer, i apt-get installed cabal. After running cabal update, i ran cabal install darcs, discovered that i needed curses, installed libncurses5-dev, discovered that i needed curl, installed that, and when it still didn't work, ran cabal install darcs -f-curl.
This worked, but darcs doesn't run from the shell when just running darcs. It was installed in ~/.cabal/bin/darcs, so i made a link from there to /bin. Darcs now works from the shell, but i am left wondering if there is a better way to do it, perhaps running cabal install under sudo?
cabal by default installs without needing administrator privileges. As such, it can't install into e.g. /usr/bin. Since $HOME/bin isn't a standard, the compromise is to put executables into ~/.cabal/bin.
You can then add ~/.cabal/bin to your path to see these executables (e.g. by appending the following to your .bashrc:
export $PATH=$PATH:~/.cabal/bin
If you have admin privledges in your machine, by all means use the --global flag.
Firstly, do not use sudo. Even when run under root, cabal builds stuff in your home directory, so using sudo indiscriminately can lead to root-owned files in your ~/.cabal. Instead, set root-cmd: sudo in your /.cabal/config, then cabal with the --global option will invoke that command as appropriate.
Secondly, using local installs is generally more convenient and safer than using global ones, because you keep your package manager and cabal separate. So you could just as well add this to your ~/.bashrc:
export PATH=$HOME/.cabal/bin:$PATH
and then continue to install stuff without using sudo at all.
See also: a slightly over-pessimistic, but nevertheless informative article on cabal package management.
The --global flag is what is needed in this case. Running sudo cabal install darcs -f-curl --global, with -f-curl because cabal couldn't find curl, --global to make it install into usr/local/bin, and sudo just to be sure, works.

Reinstall all depending packages with cabal manually [duplicate]

I want to compile my program with profiling, so I run:
$ cabal configure --enable-executable-profiling
...
$ cabal build
...
Could not find module 'Graphics.UI.GLUT':
Perhaps you havent installed the profiling libraries for package 'GLUT-2.2.2.0'?
...
$ # indeed I have not installed the prof libs for GLUT, so..
$ cabal install -p GLUT --reinstall
...
Could not find module 'Graphics.Rendering.OpenGL':
Perhaps you havent installed the profiling libraries for package 'OpenGL-2.4.0.1'?
...
So, the problem is, that unlike cabal's usual welcome behavior, cabal doesn't resolve the dependencies and install them when needing profiling libraries.
I can work around it by resolving the dependencies manually (by following errors that appear after a while of compiling):
$ cabal install -p OpenGLRaw --reinstall
$ cabal install -p StateVar --reinstall
$ cabal install -p Tensor --reinstall
$ cabal install -p ObjectName --reinstall
$ cabal install -p GLURaw --reinstall
$ cabal install -p OpenGL --reinstall
$ cabal install -p GLUT --reinstall
And then repeat for my next dependency..
Is there a better way to do this? i.e do make cabal do the work on its own as it does for normal libraries?
I've enabled library-profiling: True in my ~/.cabal/config file. From then on, any new installations will automatically enable profiling.
Unfortunately that still means I had to manually reinstall for the old packages already installed. Although, after a while of doing this manually, I now have most packages reinstalled with profiling enabled...
From a comment by Tom Lokhorst:
I do hope someone will come along with a better answer, one that would not require me to reinstall the complete Haskell Platform manually next time.
For future visitors:
The task of installing profiling versions of all installed libraries has become less of a chore, cabal (cabal-install) now keeps track of what was installed using it in the world file in the .cabal directory (on linux, that would be $HOME/.cabal, on Windows something like C:\Users\%YOU%\AppData\Roaming\cabal\, on OSX ??).
So after enabling profiling in the config file (in the same directory), and clearing GHC's package database (you can find the locations of the global and user db per ghc-pkg list nonexisting; remove the cabal-installed packages from the global database with ghc-pkg unregister packagename if you have any, rename or delete the entire user db - this is necessary because the world file only tracks explicitly installed packages, not their dependencies), installing everything with profiling support should work as follows:
$ cabal install --reinstall world --dry-run
First run with --dry-run to check for problems before actually reinstalling anything. If it would reinstall boot packages like process or directory, that's a bad sign, if you don't know how to handle it, ask on the #haskell IRC channel, one of the mailing lists, or here for guidance. If it fails to find a consistent install plan due to new versions on hackage of some packages which are incompatible with each other, that can usually be solved by editing the world file and constraining allowable versions of some packages.
Then, if you are optimistic that nothing will badly break,
$ cabal install --reinstall world
and have a nice pot of tea while GHC is busy compiling.
Daniel Fischer's answer looks good, but for some reason my ~/.cabal/world library only contained entries for libraries directly installed, and not their dependencies.
Instead, I dumped out a list of all installed libraries using
$ ghc-pkg list > list
This lists the libraries installed system-wide and locally. Therefore, I edited the list file to remove the first portion (containing libraries installed system-wide) leaving only the lines after /home/<user>/.ghc/.... Finally, I ran
$ cabal install --reinstall $(cat list)
This worked for me. You should maybe do --dry-run first. Then go make a pot of tea. Or bake a cake.
it appears there is no way right now: Ticket #282 - profiling versions of libraries not managed well "As usual the problem is lack of devevloper time to implement all these
nice features we all want."
For visitors 2016+: Just install ghc-prof
Debian Linux Systems:
sudo apt-get install ghc-prof
Arch Linux Systems:
sudo pacman -S ghc-prof

How do you install packages/libraries without Cabal or Cabal-Install?

I'm trying to set up Haskell from scratch, on Ubuntu 11.04, without using the outdated Debian repository or Haskell-Platform.
I've installed GHC-7.0.4 from source with no problem, and now need to install Cabal (which appears to already be included in GHC in /usr/local/lib/ghc-7.0.4/Cabal-1.10.2.0) and Cabal Install.
The latter specifies several dependencies (parsec and network), each of which has several dependencies of their own (mtl, text, etc).
What's the command to install these packages, that I downloaded from hackage in tar.gz form?
Unpack, then runhaskell doesn't work.
I see Setup.lhs, but it's not clear what that's for or how to use it.
Most of the Haskell documentation I've found assumes you've installed from a repo or Haskell-Package and doesn't really explain this well.
cabal-install has a shell script that does this. If you download it from hackage and install it, you can start bootstrap.sh to install cabal-install. You can then use it to install other packages.
There are two different packages: Cabal and cabal-install. Cabal is a library, and cabal-install is an executable named cabal.
To install a package, cabal-install is an optional convenience wrapper around Cabal, but Cabal is required.
According to http://hackage.haskell.org/trac/ghc/wiki/Commentary/Libraries , Cabal is a 'zero-boot' package, so when you build GHC, Cabal and its dependencies are built for you automatically.
You can use ghc-pkg executable to check which packages are already installed:
# ghc-pkg list
Check if Cabal is in the list after you build GHC. If yes, you can install more packages without cabal-install using this documentation:
http://haskell.org/haskellwiki/Cabal/How_to_install_a_Cabal_package
I suggest you to install cabal-install first, and then install everything else using cabal-install executable. A usual commandine for global installation is this:
# runhaskell Setup configure
# runhaskell Setup build
# sudo runhaskell Setup install
Unpack a package tarball and run the commands in the folder with Setup.hs or Setup.lhs files. Note that a per-user non-root installation is also supported - Use runhaskell Setup configure --user
When you install cabal executable and its dependencies this way, use cabal install {package-name} to install more packages.
Note that Haskell Platform exists mostly because of the pain of installing cabal-install by yourself.

Cabal not installing dependencies when needing profiling libraries?

I want to compile my program with profiling, so I run:
$ cabal configure --enable-executable-profiling
...
$ cabal build
...
Could not find module 'Graphics.UI.GLUT':
Perhaps you havent installed the profiling libraries for package 'GLUT-2.2.2.0'?
...
$ # indeed I have not installed the prof libs for GLUT, so..
$ cabal install -p GLUT --reinstall
...
Could not find module 'Graphics.Rendering.OpenGL':
Perhaps you havent installed the profiling libraries for package 'OpenGL-2.4.0.1'?
...
So, the problem is, that unlike cabal's usual welcome behavior, cabal doesn't resolve the dependencies and install them when needing profiling libraries.
I can work around it by resolving the dependencies manually (by following errors that appear after a while of compiling):
$ cabal install -p OpenGLRaw --reinstall
$ cabal install -p StateVar --reinstall
$ cabal install -p Tensor --reinstall
$ cabal install -p ObjectName --reinstall
$ cabal install -p GLURaw --reinstall
$ cabal install -p OpenGL --reinstall
$ cabal install -p GLUT --reinstall
And then repeat for my next dependency..
Is there a better way to do this? i.e do make cabal do the work on its own as it does for normal libraries?
I've enabled library-profiling: True in my ~/.cabal/config file. From then on, any new installations will automatically enable profiling.
Unfortunately that still means I had to manually reinstall for the old packages already installed. Although, after a while of doing this manually, I now have most packages reinstalled with profiling enabled...
From a comment by Tom Lokhorst:
I do hope someone will come along with a better answer, one that would not require me to reinstall the complete Haskell Platform manually next time.
For future visitors:
The task of installing profiling versions of all installed libraries has become less of a chore, cabal (cabal-install) now keeps track of what was installed using it in the world file in the .cabal directory (on linux, that would be $HOME/.cabal, on Windows something like C:\Users\%YOU%\AppData\Roaming\cabal\, on OSX ??).
So after enabling profiling in the config file (in the same directory), and clearing GHC's package database (you can find the locations of the global and user db per ghc-pkg list nonexisting; remove the cabal-installed packages from the global database with ghc-pkg unregister packagename if you have any, rename or delete the entire user db - this is necessary because the world file only tracks explicitly installed packages, not their dependencies), installing everything with profiling support should work as follows:
$ cabal install --reinstall world --dry-run
First run with --dry-run to check for problems before actually reinstalling anything. If it would reinstall boot packages like process or directory, that's a bad sign, if you don't know how to handle it, ask on the #haskell IRC channel, one of the mailing lists, or here for guidance. If it fails to find a consistent install plan due to new versions on hackage of some packages which are incompatible with each other, that can usually be solved by editing the world file and constraining allowable versions of some packages.
Then, if you are optimistic that nothing will badly break,
$ cabal install --reinstall world
and have a nice pot of tea while GHC is busy compiling.
Daniel Fischer's answer looks good, but for some reason my ~/.cabal/world library only contained entries for libraries directly installed, and not their dependencies.
Instead, I dumped out a list of all installed libraries using
$ ghc-pkg list > list
This lists the libraries installed system-wide and locally. Therefore, I edited the list file to remove the first portion (containing libraries installed system-wide) leaving only the lines after /home/<user>/.ghc/.... Finally, I ran
$ cabal install --reinstall $(cat list)
This worked for me. You should maybe do --dry-run first. Then go make a pot of tea. Or bake a cake.
it appears there is no way right now: Ticket #282 - profiling versions of libraries not managed well "As usual the problem is lack of devevloper time to implement all these
nice features we all want."
For visitors 2016+: Just install ghc-prof
Debian Linux Systems:
sudo apt-get install ghc-prof
Arch Linux Systems:
sudo pacman -S ghc-prof

Resources