How to use the command `ghcup` (with examples)
The ghcup
command is a Haskell toolchain installer that allows users to install, manage, and update Haskell toolchains. This article will provide examples of various use cases of the ghcup
command and explain each use case in detail.
Use case 1: Start the interactive TUI
Code:
ghcup tui
Motivation:
The interactive TUI (Text User Interface) provided by ghcup
allows users to easily navigate through available Haskell toolchains and perform actions such as installing or setting a specific version.
Explanation:
By running the command ghcup tui
, the interactive TUI interface of ghcup
will start, enabling users to interactively select and execute various actions related to Haskell toolchains.
Example output:
Welcome to ghcup!
Please choose an action:
1. Install GHC version
2. Set active GHC version
3. Install cabal-install
4. Upgrade ghcup
Please enter the number of the action you want to perform (or 'q' to quit):
Use case 2: List available GHC/cabal versions
Code:
ghcup list
Motivation: Listing available GHC/cabal versions can be helpful when deciding which version to install or set as the active version.
Explanation:
Running the command ghcup list
will display a list of all available GHC and cabal versions that can be installed or set as the active version.
Example output:
Available GHC versions:
- ghc-8.10.7
- ghc-9.2.1
Available cabal-install versions:
- cabal-install-3.6.2.0
- cabal-install-3.6.3.0
Use case 3: Install the recommended GHC version
Code:
ghcup install ghc
Motivation: Installing the recommended GHC version ensures that the user has the most stable and compatible version of GHC for their Haskell projects.
Explanation:
By running the command ghcup install ghc
, ghcup
will automatically install the recommended GHC version on the user’s system.
Example output:
Downloading GHC version 9.2.1
Installing GHC version 9.2.1
GHC version 9.2.1 has been successfully installed.
Use case 4: Install a specific GHC version
Code:
ghcup install ghc version
Motivation: Installing a specific GHC version can be useful when working on projects that require a specific version for compatibility or testing purposes.
Explanation:
By replacing version
with the desired GHC version, running the command ghcup install ghc version
will download and install the specified GHC version on the user’s system.
Example output:
Downloading GHC version 8.10.7
Installing GHC version 8.10.7
GHC version 8.10.7 has been successfully installed.
Use case 5: Set the currently “active” GHC version
Code:
ghcup set ghc version
Motivation: Setting the active GHC version allows users to switch between different installed GHC versions easily.
Explanation:
By replacing version
with the desired GHC version, running the command ghcup set ghc version
will set the specified GHC version as the active version.
Example output:
Setting GHC version 8.10.7 as active.
Use case 6: Install cabal-install
Code:
ghcup install cabal
Motivation: Installing cabal-install is necessary for managing Haskell packages and building Haskell projects.
Explanation:
Running the command ghcup install cabal
will download and install cabal-install on the user’s system.
Example output:
Downloading cabal-install version 3.6.3.0
Installing cabal-install version 3.6.3.0
cabal-install version 3.6.3.0 has been successfully installed.
Use case 7: Update ghcup
itself
Code:
ghcup upgrade
Motivation:
Updating ghcup
ensures that the user has the latest version of the Haskell toolchain installer, which may include bug fixes or new features.
Explanation:
Running the command ghcup upgrade
will check for updates to ghcup
and if a new version is available, it will be downloaded and installed.
Example output:
Checking for updates...
Downloading ghcup version 1.5.0
Installing ghcup version 1.5.0
ghcup version 1.5.0 has been successfully installed.
Conclusion:
In this article, we explored various use cases of the ghcup
command, which serves as a Haskell toolchain installer. We covered how to start the interactive TUI, list available GHC/cabal versions, install or set specific GHC versions, install cabal-install, and update ghcup
itself. These examples should help users effectively manage their Haskell toolchains using ghcup
.