How to use jenv with Fish shell on Linux?

I downloaded jenv using the official instructions, added it to the PATH and then tried to init it, using the command given in the instructions, but it throws the following error:

> source (jenv init -|psub)

Command 'hash' not found, did you mean:
  command 'bash' from deb bash (5.1-2ubuntu1)
  command 'sash' from deb sash (3.8-5)
  ...
Try: sudo apt install <deb name>
/tmp/.psub.LxsYuMSHNC (line 1): 
hash -r
^
from sourcing file /tmp/.psub.LxsYuMSHNC
    called on line 14 of file /tmp/.psub.Z8yofQashD
in function 'jenv' with arguments 'rehash'
    called on line 7 of file /tmp/.psub.lD4Y0jQZfO
from sourcing file /tmp/.psub.lD4Y0jQZfO

I understand that the hash utility is a bash utility, but can you somehow make it work in fish? There is official documentation for it, there exist fisher plugins for it, so I doubt that it is not supported at all.

I have found one post that describes my problem on Reddit, but it is rather old, and the solution does not work for me.

I temporarily fixed it by using source (jenv init --no-rehash -|psub) instead of the official command, which skips the hash function altogether. Is there any way to make it work without the workaround?


Solution 1:

You may have the best workaround at the moment.

This note at the bottom of the README mentions its known Fish issues, and this issue mentions that the maintainer doesn't have time for the project any longer, and recommends asdf and SDKMan as "better" options than jenv.

I've used asdf under Fish, but it's been over a year. I don't recall how well it ran, nor did I use it to manage Java versions. I seem to recall minor installation issues, but I believe these were due to my personal environment preference.

But it may be worth giving asdf or SDKMan a try based on the current maintenance status of jenv and its known issues with Fish.