How to set a specific version of Java as JAVA_HOME in Fish in macOS












0















I was using Bash as my default shell on macOS but I decided to switch to Fish.



I am trying to switch between different versions of Java. In bash it was done using the ~/.bash_profile



export JAVA_HOME=`/usr/libexec/java_home -v 1.7`


I have set the equivalent on Fish ~/.config/fish/fish_variables



set -x JAVA_HOME `/usr/libexec/java_home -v 1.7`


Unfortunately, Java version is not being changed. How can I set environment variables (specific version of Java, in particular) using ~/.config/fish/fish_variables?



UPDATE:



According to the FAQ, instead of ~/.config/fish/fish_variables, ~/.config/fish/config.fish should be used. Also I created ~/.config/fish/fish.config instead of ~/.config/fish/config.fish.










share|improve this question

























  • The file ~/.config/fish/fish_variables has no intrinsic meaning to fish. That is, fish won't automatically source the contents of that file.

    – Kurtis Rader
    Feb 3 at 22:28











  • @KurtisRader According to FAQ fishshell.com/docs/2.2/faq.html I also tried to create ~/.config/fish/config.fish, but it did not help.

    – kmb
    Feb 3 at 22:45






  • 2





    That FAQ says nothing about a file named fish_variables. The only fish user config file that is sourced automatically by every fish process is ~/.config/fish/config.fish. If you put a echo hello in that file and start a new fish shell do you see the word "hello"?

    – Kurtis Rader
    Feb 3 at 22:55











  • @KurtisRader There was a typo on my side... I have created ~/.config/fish/fish.config instead of ~/.config/fish/config.fish. Thanks for your help!

    – kmb
    Feb 3 at 23:37






  • 1





    @kmb You should mark Jake's answer as solving your problem.

    – Kurtis Rader
    Feb 4 at 2:01
















0















I was using Bash as my default shell on macOS but I decided to switch to Fish.



I am trying to switch between different versions of Java. In bash it was done using the ~/.bash_profile



export JAVA_HOME=`/usr/libexec/java_home -v 1.7`


I have set the equivalent on Fish ~/.config/fish/fish_variables



set -x JAVA_HOME `/usr/libexec/java_home -v 1.7`


Unfortunately, Java version is not being changed. How can I set environment variables (specific version of Java, in particular) using ~/.config/fish/fish_variables?



UPDATE:



According to the FAQ, instead of ~/.config/fish/fish_variables, ~/.config/fish/config.fish should be used. Also I created ~/.config/fish/fish.config instead of ~/.config/fish/config.fish.










share|improve this question

























  • The file ~/.config/fish/fish_variables has no intrinsic meaning to fish. That is, fish won't automatically source the contents of that file.

    – Kurtis Rader
    Feb 3 at 22:28











  • @KurtisRader According to FAQ fishshell.com/docs/2.2/faq.html I also tried to create ~/.config/fish/config.fish, but it did not help.

    – kmb
    Feb 3 at 22:45






  • 2





    That FAQ says nothing about a file named fish_variables. The only fish user config file that is sourced automatically by every fish process is ~/.config/fish/config.fish. If you put a echo hello in that file and start a new fish shell do you see the word "hello"?

    – Kurtis Rader
    Feb 3 at 22:55











  • @KurtisRader There was a typo on my side... I have created ~/.config/fish/fish.config instead of ~/.config/fish/config.fish. Thanks for your help!

    – kmb
    Feb 3 at 23:37






  • 1





    @kmb You should mark Jake's answer as solving your problem.

    – Kurtis Rader
    Feb 4 at 2:01














0












0








0








I was using Bash as my default shell on macOS but I decided to switch to Fish.



I am trying to switch between different versions of Java. In bash it was done using the ~/.bash_profile



export JAVA_HOME=`/usr/libexec/java_home -v 1.7`


I have set the equivalent on Fish ~/.config/fish/fish_variables



set -x JAVA_HOME `/usr/libexec/java_home -v 1.7`


Unfortunately, Java version is not being changed. How can I set environment variables (specific version of Java, in particular) using ~/.config/fish/fish_variables?



UPDATE:



According to the FAQ, instead of ~/.config/fish/fish_variables, ~/.config/fish/config.fish should be used. Also I created ~/.config/fish/fish.config instead of ~/.config/fish/config.fish.










share|improve this question
















I was using Bash as my default shell on macOS but I decided to switch to Fish.



I am trying to switch between different versions of Java. In bash it was done using the ~/.bash_profile



export JAVA_HOME=`/usr/libexec/java_home -v 1.7`


I have set the equivalent on Fish ~/.config/fish/fish_variables



set -x JAVA_HOME `/usr/libexec/java_home -v 1.7`


Unfortunately, Java version is not being changed. How can I set environment variables (specific version of Java, in particular) using ~/.config/fish/fish_variables?



UPDATE:



According to the FAQ, instead of ~/.config/fish/fish_variables, ~/.config/fish/config.fish should be used. Also I created ~/.config/fish/fish.config instead of ~/.config/fish/config.fish.







macos bash java fish






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 4 at 14:52









JakeGould

31.6k1096138




31.6k1096138










asked Feb 3 at 21:09









kmbkmb

1155




1155













  • The file ~/.config/fish/fish_variables has no intrinsic meaning to fish. That is, fish won't automatically source the contents of that file.

    – Kurtis Rader
    Feb 3 at 22:28











  • @KurtisRader According to FAQ fishshell.com/docs/2.2/faq.html I also tried to create ~/.config/fish/config.fish, but it did not help.

    – kmb
    Feb 3 at 22:45






  • 2





    That FAQ says nothing about a file named fish_variables. The only fish user config file that is sourced automatically by every fish process is ~/.config/fish/config.fish. If you put a echo hello in that file and start a new fish shell do you see the word "hello"?

    – Kurtis Rader
    Feb 3 at 22:55











  • @KurtisRader There was a typo on my side... I have created ~/.config/fish/fish.config instead of ~/.config/fish/config.fish. Thanks for your help!

    – kmb
    Feb 3 at 23:37






  • 1





    @kmb You should mark Jake's answer as solving your problem.

    – Kurtis Rader
    Feb 4 at 2:01



















  • The file ~/.config/fish/fish_variables has no intrinsic meaning to fish. That is, fish won't automatically source the contents of that file.

    – Kurtis Rader
    Feb 3 at 22:28











  • @KurtisRader According to FAQ fishshell.com/docs/2.2/faq.html I also tried to create ~/.config/fish/config.fish, but it did not help.

    – kmb
    Feb 3 at 22:45






  • 2





    That FAQ says nothing about a file named fish_variables. The only fish user config file that is sourced automatically by every fish process is ~/.config/fish/config.fish. If you put a echo hello in that file and start a new fish shell do you see the word "hello"?

    – Kurtis Rader
    Feb 3 at 22:55











  • @KurtisRader There was a typo on my side... I have created ~/.config/fish/fish.config instead of ~/.config/fish/config.fish. Thanks for your help!

    – kmb
    Feb 3 at 23:37






  • 1





    @kmb You should mark Jake's answer as solving your problem.

    – Kurtis Rader
    Feb 4 at 2:01

















The file ~/.config/fish/fish_variables has no intrinsic meaning to fish. That is, fish won't automatically source the contents of that file.

– Kurtis Rader
Feb 3 at 22:28





The file ~/.config/fish/fish_variables has no intrinsic meaning to fish. That is, fish won't automatically source the contents of that file.

– Kurtis Rader
Feb 3 at 22:28













@KurtisRader According to FAQ fishshell.com/docs/2.2/faq.html I also tried to create ~/.config/fish/config.fish, but it did not help.

– kmb
Feb 3 at 22:45





@KurtisRader According to FAQ fishshell.com/docs/2.2/faq.html I also tried to create ~/.config/fish/config.fish, but it did not help.

– kmb
Feb 3 at 22:45




2




2





That FAQ says nothing about a file named fish_variables. The only fish user config file that is sourced automatically by every fish process is ~/.config/fish/config.fish. If you put a echo hello in that file and start a new fish shell do you see the word "hello"?

– Kurtis Rader
Feb 3 at 22:55





That FAQ says nothing about a file named fish_variables. The only fish user config file that is sourced automatically by every fish process is ~/.config/fish/config.fish. If you put a echo hello in that file and start a new fish shell do you see the word "hello"?

– Kurtis Rader
Feb 3 at 22:55













@KurtisRader There was a typo on my side... I have created ~/.config/fish/fish.config instead of ~/.config/fish/config.fish. Thanks for your help!

– kmb
Feb 3 at 23:37





@KurtisRader There was a typo on my side... I have created ~/.config/fish/fish.config instead of ~/.config/fish/config.fish. Thanks for your help!

– kmb
Feb 3 at 23:37




1




1





@kmb You should mark Jake's answer as solving your problem.

– Kurtis Rader
Feb 4 at 2:01





@kmb You should mark Jake's answer as solving your problem.

– Kurtis Rader
Feb 4 at 2:01










1 Answer
1






active

oldest

votes


















1














While I am not deeply familiar with Fish, based on what I am reading it seems like the issue is with the backticks in your command:



/usr/libexec/java_home -v 1.7


You see that is just like this in Bash:



$(/usr/libexec/java_home -v 1.7)


Keep that in mind and look at this Fish FAQ entry:




How do I run a subcommand? The backtick doesn't work!



fish uses parentheses for subcommands. For example:



for i in (ls)
echo $i
end



Knowing that the config line should most likely be:



set -x JAVA_HOME (/usr/libexec/java_home -v 1.7)





share|improve this answer
























  • Unfortunately, parenthesis are also not working.

    – kmb
    Feb 3 at 21:53











  • @kbm You need to provide more information. Saying it's "not working" isn't helpful. If you type that set -x ... command interactively what happens?

    – Kurtis Rader
    Feb 3 at 22:29











  • @KurtisRader set -x JAVA_HOME (/usr/libexec/java_home -v 1.7) entered directly to shell works fine. After this action java version is changed to 1.7. After closing and opening terminal again, java is set back to version 11. I want to change it permanently, but I need to keep different version on java installed.

    – kmb
    Feb 3 at 22:42











  • @kmb Well, my command is just a different version of what you added to ~/.config/fish/fish_variables. Did you test this variant with parenthesis when it was placed in ~/.config/fish/fish_variables?

    – JakeGould
    Feb 4 at 2:05






  • 1





    @JakeGould Parenthesis instead of backticks was one of two errors - thank you for pointing it out. The second thing that was wrong, was the file used by me for configuration. Instead of ~/.config/fish/fish_variables, ~/.config/fish/config.fish should be used. I have updated question with this information.

    – kmb
    Feb 4 at 10:54











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1401673%2fhow-to-set-a-specific-version-of-java-as-java-home-in-fish-in-macos%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














While I am not deeply familiar with Fish, based on what I am reading it seems like the issue is with the backticks in your command:



/usr/libexec/java_home -v 1.7


You see that is just like this in Bash:



$(/usr/libexec/java_home -v 1.7)


Keep that in mind and look at this Fish FAQ entry:




How do I run a subcommand? The backtick doesn't work!



fish uses parentheses for subcommands. For example:



for i in (ls)
echo $i
end



Knowing that the config line should most likely be:



set -x JAVA_HOME (/usr/libexec/java_home -v 1.7)





share|improve this answer
























  • Unfortunately, parenthesis are also not working.

    – kmb
    Feb 3 at 21:53











  • @kbm You need to provide more information. Saying it's "not working" isn't helpful. If you type that set -x ... command interactively what happens?

    – Kurtis Rader
    Feb 3 at 22:29











  • @KurtisRader set -x JAVA_HOME (/usr/libexec/java_home -v 1.7) entered directly to shell works fine. After this action java version is changed to 1.7. After closing and opening terminal again, java is set back to version 11. I want to change it permanently, but I need to keep different version on java installed.

    – kmb
    Feb 3 at 22:42











  • @kmb Well, my command is just a different version of what you added to ~/.config/fish/fish_variables. Did you test this variant with parenthesis when it was placed in ~/.config/fish/fish_variables?

    – JakeGould
    Feb 4 at 2:05






  • 1





    @JakeGould Parenthesis instead of backticks was one of two errors - thank you for pointing it out. The second thing that was wrong, was the file used by me for configuration. Instead of ~/.config/fish/fish_variables, ~/.config/fish/config.fish should be used. I have updated question with this information.

    – kmb
    Feb 4 at 10:54
















1














While I am not deeply familiar with Fish, based on what I am reading it seems like the issue is with the backticks in your command:



/usr/libexec/java_home -v 1.7


You see that is just like this in Bash:



$(/usr/libexec/java_home -v 1.7)


Keep that in mind and look at this Fish FAQ entry:




How do I run a subcommand? The backtick doesn't work!



fish uses parentheses for subcommands. For example:



for i in (ls)
echo $i
end



Knowing that the config line should most likely be:



set -x JAVA_HOME (/usr/libexec/java_home -v 1.7)





share|improve this answer
























  • Unfortunately, parenthesis are also not working.

    – kmb
    Feb 3 at 21:53











  • @kbm You need to provide more information. Saying it's "not working" isn't helpful. If you type that set -x ... command interactively what happens?

    – Kurtis Rader
    Feb 3 at 22:29











  • @KurtisRader set -x JAVA_HOME (/usr/libexec/java_home -v 1.7) entered directly to shell works fine. After this action java version is changed to 1.7. After closing and opening terminal again, java is set back to version 11. I want to change it permanently, but I need to keep different version on java installed.

    – kmb
    Feb 3 at 22:42











  • @kmb Well, my command is just a different version of what you added to ~/.config/fish/fish_variables. Did you test this variant with parenthesis when it was placed in ~/.config/fish/fish_variables?

    – JakeGould
    Feb 4 at 2:05






  • 1





    @JakeGould Parenthesis instead of backticks was one of two errors - thank you for pointing it out. The second thing that was wrong, was the file used by me for configuration. Instead of ~/.config/fish/fish_variables, ~/.config/fish/config.fish should be used. I have updated question with this information.

    – kmb
    Feb 4 at 10:54














1












1








1







While I am not deeply familiar with Fish, based on what I am reading it seems like the issue is with the backticks in your command:



/usr/libexec/java_home -v 1.7


You see that is just like this in Bash:



$(/usr/libexec/java_home -v 1.7)


Keep that in mind and look at this Fish FAQ entry:




How do I run a subcommand? The backtick doesn't work!



fish uses parentheses for subcommands. For example:



for i in (ls)
echo $i
end



Knowing that the config line should most likely be:



set -x JAVA_HOME (/usr/libexec/java_home -v 1.7)





share|improve this answer













While I am not deeply familiar with Fish, based on what I am reading it seems like the issue is with the backticks in your command:



/usr/libexec/java_home -v 1.7


You see that is just like this in Bash:



$(/usr/libexec/java_home -v 1.7)


Keep that in mind and look at this Fish FAQ entry:




How do I run a subcommand? The backtick doesn't work!



fish uses parentheses for subcommands. For example:



for i in (ls)
echo $i
end



Knowing that the config line should most likely be:



set -x JAVA_HOME (/usr/libexec/java_home -v 1.7)






share|improve this answer












share|improve this answer



share|improve this answer










answered Feb 3 at 21:23









JakeGouldJakeGould

31.6k1096138




31.6k1096138













  • Unfortunately, parenthesis are also not working.

    – kmb
    Feb 3 at 21:53











  • @kbm You need to provide more information. Saying it's "not working" isn't helpful. If you type that set -x ... command interactively what happens?

    – Kurtis Rader
    Feb 3 at 22:29











  • @KurtisRader set -x JAVA_HOME (/usr/libexec/java_home -v 1.7) entered directly to shell works fine. After this action java version is changed to 1.7. After closing and opening terminal again, java is set back to version 11. I want to change it permanently, but I need to keep different version on java installed.

    – kmb
    Feb 3 at 22:42











  • @kmb Well, my command is just a different version of what you added to ~/.config/fish/fish_variables. Did you test this variant with parenthesis when it was placed in ~/.config/fish/fish_variables?

    – JakeGould
    Feb 4 at 2:05






  • 1





    @JakeGould Parenthesis instead of backticks was one of two errors - thank you for pointing it out. The second thing that was wrong, was the file used by me for configuration. Instead of ~/.config/fish/fish_variables, ~/.config/fish/config.fish should be used. I have updated question with this information.

    – kmb
    Feb 4 at 10:54



















  • Unfortunately, parenthesis are also not working.

    – kmb
    Feb 3 at 21:53











  • @kbm You need to provide more information. Saying it's "not working" isn't helpful. If you type that set -x ... command interactively what happens?

    – Kurtis Rader
    Feb 3 at 22:29











  • @KurtisRader set -x JAVA_HOME (/usr/libexec/java_home -v 1.7) entered directly to shell works fine. After this action java version is changed to 1.7. After closing and opening terminal again, java is set back to version 11. I want to change it permanently, but I need to keep different version on java installed.

    – kmb
    Feb 3 at 22:42











  • @kmb Well, my command is just a different version of what you added to ~/.config/fish/fish_variables. Did you test this variant with parenthesis when it was placed in ~/.config/fish/fish_variables?

    – JakeGould
    Feb 4 at 2:05






  • 1





    @JakeGould Parenthesis instead of backticks was one of two errors - thank you for pointing it out. The second thing that was wrong, was the file used by me for configuration. Instead of ~/.config/fish/fish_variables, ~/.config/fish/config.fish should be used. I have updated question with this information.

    – kmb
    Feb 4 at 10:54

















Unfortunately, parenthesis are also not working.

– kmb
Feb 3 at 21:53





Unfortunately, parenthesis are also not working.

– kmb
Feb 3 at 21:53













@kbm You need to provide more information. Saying it's "not working" isn't helpful. If you type that set -x ... command interactively what happens?

– Kurtis Rader
Feb 3 at 22:29





@kbm You need to provide more information. Saying it's "not working" isn't helpful. If you type that set -x ... command interactively what happens?

– Kurtis Rader
Feb 3 at 22:29













@KurtisRader set -x JAVA_HOME (/usr/libexec/java_home -v 1.7) entered directly to shell works fine. After this action java version is changed to 1.7. After closing and opening terminal again, java is set back to version 11. I want to change it permanently, but I need to keep different version on java installed.

– kmb
Feb 3 at 22:42





@KurtisRader set -x JAVA_HOME (/usr/libexec/java_home -v 1.7) entered directly to shell works fine. After this action java version is changed to 1.7. After closing and opening terminal again, java is set back to version 11. I want to change it permanently, but I need to keep different version on java installed.

– kmb
Feb 3 at 22:42













@kmb Well, my command is just a different version of what you added to ~/.config/fish/fish_variables. Did you test this variant with parenthesis when it was placed in ~/.config/fish/fish_variables?

– JakeGould
Feb 4 at 2:05





@kmb Well, my command is just a different version of what you added to ~/.config/fish/fish_variables. Did you test this variant with parenthesis when it was placed in ~/.config/fish/fish_variables?

– JakeGould
Feb 4 at 2:05




1




1





@JakeGould Parenthesis instead of backticks was one of two errors - thank you for pointing it out. The second thing that was wrong, was the file used by me for configuration. Instead of ~/.config/fish/fish_variables, ~/.config/fish/config.fish should be used. I have updated question with this information.

– kmb
Feb 4 at 10:54





@JakeGould Parenthesis instead of backticks was one of two errors - thank you for pointing it out. The second thing that was wrong, was the file used by me for configuration. Instead of ~/.config/fish/fish_variables, ~/.config/fish/config.fish should be used. I have updated question with this information.

– kmb
Feb 4 at 10:54


















draft saved

draft discarded




















































Thanks for contributing an answer to Super User!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1401673%2fhow-to-set-a-specific-version-of-java-as-java-home-in-fish-in-macos%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Probability when a professor distributes a quiz and homework assignment to a class of n students.

Aardman Animations

Are they similar matrix