Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PATH should be updated to include GHC binaries in .profile rather than .bashrc #763

Closed
ChaiTRex opened this issue Jan 25, 2023 · 4 comments

Comments

@ChaiTRex
Copy link

ChaiTRex commented Jan 25, 2023

PATH should be updated to include GHC binaries via .profile rather than .bashrc. This tends to makes it work for people who use something other than bash as their shell. It's also what rustup does.

rustup's alterations to startup files

Last line of ~/.profile:

. "$HOME/.cargo/env"

Contents of ~/.cargo/env:

#!/bin/sh
# rustup shell setup
# affix colons on either side of $PATH to simplify matching
case ":${PATH}:" in
    *:"$HOME/.cargo/bin":*)
        ;;
    *)
        # Prepending path in case a system-installed rustc needs to be overridden
        export PATH="$HOME/.cargo/bin:$PATH"
        ;;
esac

Differences in the results of the two approaches

bash results

With the default bash that I installed rustup and ghcup under:

$ rustup --version
rustup 1.25.1 (bb60b1e89 2022-07-12)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.66.1 (90743e729 2023-01-10)`

$ cargo version
cargo 1.66.1 (ad779e08b 2023-01-10)

$ ghcup --version
The GHCup Haskell installer, version 0.1.19.0

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 9.4.4

zsh results

After installing zsh, using chsh -s /usr/bin/zsh, and restarting the computer:

% rustup --version
rustup 1.25.1 (bb60b1e89 2022-07-12)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.66.1 (90743e729 2023-01-10)`

% cargo version
cargo 1.66.1 (ad779e08b 2023-01-10)

% ghcup --version
zsh: command not found: ghcup

% ghc --version
zsh: command not found: ghc

fish results

After installing fish, using chsh -s /usr/bin/fish, and restarting the computer:

~> rustup --version
rustup 1.25.1 (bb60b1e89 2022-07-12)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.66.1 (90743e729 2023-01-10)`

~> cargo version
cargo 1.66.1 (ad779e08b 2023-01-10)

~> ghcup --version
ghcup: command not found

~ [127]> ghc --version
Command 'ghc' not found, but can be installed with:
sudo apt install ghc
@hasufell
Copy link
Member

.profile is not guaranteed to be sourced either. This depends on user configuration.

@georgefst
Copy link

Previously discussed in this thread: haskell/haskell-language-server#236. Though various improvements have made this less of an issue for HLS than it was back then.

I still feel ~/.profile would be a better default then ~/.bashrc on all systems that I've used. But I'm not quite sure what the guarantees are in general.

@hasufell
Copy link
Member

hasufell commented Feb 17, 2023

There are many caveats, e.g. for login shell (from the manpage):

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

So if .bash_profile exists, only that is read.

Then the non-login case, which is probably the more common one:

When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc.

In this case, it doesn't read .profile at all. What distros do here is to simply source it at the beginning of .bashrc, but that's a convention, not a guarantee.

@hasufell
Copy link
Member

Since it's safe source the env file multiple times, I guess we can stuff it into whatever we find.

@hasufell hasufell added this to the 0.1.22.0 milestone Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants