有办法在启动Shell时激活默认的opam开关吗?

huangapple go评论132阅读模式
英文:

Is there a way to activate the default opam switch on shell startup?

问题

代码部分不需要翻译。以下是翻译好的部分:

"It's very tedious to have to activate the default switch every time I want to start using ocaml with eval $(opam env --switch=default --set-switch). I was given an option when I first initialized opam to update my .zshrc with a line to do this on startup but I must have missed it because the initialization continued on without my input. I tried manually adding the line to my .zshrc but the switch that's activated is not my default switch, which uses ocaml v5.0.0. Instead, it activates another switch I created with v4.14.0."

中文翻译:

"每次我想要开始使用 ocaml 时都必须激活默认的开关,这真的很烦人,使用 eval $(opam env --switch=default --set-switch)。当我首次初始化 opam 时,我被给予一个选项,可以更新我的 .zshrc,以便在启动时执行此操作,但我可能错过了它,因为初始化继续进行,没有我的输入。我尝试手动将该行添加到我的 .zshrc,但激活的开关不是我的默认开关,而是使用 ocaml v5.0.0 的另一个开关。相反,它激活了我创建的一个开关,其中使用了 v4.14.0。"

英文:

It's very tedious to have to activate the default switch every time I want to start using ocaml with eval $(opam env --switch=default --set-switch). I was given an option when I first initialized opam to update my .zshrc with a line to do this on startup but I must have missed it because the initialization continued on without my input. I tried manually adding the line to my .zshrc but the switch that's activated is not my default switch, which uses ocaml v5.0.0. Instead, it activates another switch I created with v4.14.0.

For context, the line I added to my runtime config was

[[ ! -r /Users/USERNAME/.opam/opam-init/init.zsh ]] || source /Users/USERNAME/.opam/opam-init/init.zsh  > /dev/null 2> /dev/null

Maybe the answer to my question is that it's not recommended to activate a switch by default?

答案1

得分: 1

以下是翻译好的部分:

"It is generally recommended to activate a switch by default if you always want to use a specific version of a tool or language. In your case, it seems that the line you added to your .zshrc is not activating the default switch, but rather a different switch you created with version 4.14.0 of OCaml.

要始终使用特定版本的工具或语言,通常建议默认激活开关。在您的情况下,似乎您添加到.zshrc的那行代码并没有激活默认开关,而是激活了您使用OCaml版本4.14.0创建的不同开关。

To activate the default switch every time you start a new terminal session, you can add the following line to your .zshrc file:

要在每次启动新终端会话时激活默认开关,您可以将以下行添加到您的.zshrc文件:

eval $(opam env --switch=default --set-switch)

This will activate the default switch and set the environment variables for that switch. Make sure to remove any other lines that activate a different switch.

这将激活默认开关并设置该开关的环境变量。请确保删除激活其他开关的任何其他行。

After adding this line to your .zshrc file, run the following command to source your updated .zshrc file:

在将此行添加到.zshrc文件后,运行以下命令以加载更新后的.zshrc文件:

source ~/.zshrc

This should activate the default switch every time you start a new terminal session.

这将在每次启动新终端会话时激活默认开关。"

英文:

It is generally recommended to activate a switch by default if you always want to use a specific version of a tool or language. In your case, it seems that the line you added to your .zshrc is not activating the default switch, but rather a different switch you created with version 4.14.0 of OCaml.

To activate the default switch every time you start a new terminal session, you can add the following line to your .zshrc file:

eval $(opam env --switch=default --set-switch)

This will activate the default switch and set the environment variables for that switch. Make sure to remove any other lines that activate a different switch.

After adding this line to your .zshrc file, run the following command to source your updated .zshrc file:

source ~/.zshrc

This should activate the default switch every time you start a new terminal session.

huangapple
  • 本文由 发表于 2023年3月9日 23:33:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75686784.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定