Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

JAVA_HOME is not set correctly after adding and appending to PATH

Ubuntu 14.04 LTS Bash version 4.3.11(1)-release

I've added $JAVA_HOME to ~/.profile (and .bash_profile) like this:

But still typing echo $JAVA_HOME yields:

DsCpp's user avatar

  • The most likely explanation is that JAVA_HOME is set again later in the initialisation file sequence. Try grep JAVA_HOME .profile .bash* to check. However, JAVA_HOME=$(/usr/bin/java) is wrong: this sets JAVA_HOME to the first token in the output from running /usr/bin/java , but this generates help text on standard error and nothing on standard output, so JAVA_HOME is set to an empty string. –  AFH Nov 14, 2018 at 14:07

Using the variable assignment with a $() tells Linux to do a command substitution. So, it is trying to run the command /usr/bin/java and assign the output to the variable.

You should use:

Then to make the new variables live, execute your profile script:

Note the extra . at the beginning. Without it the variable assignment would only persist within the scope of the script.

Appleoddity's user avatar

You must log in to answer this question.

Not the answer you're looking for browse other questions tagged ubuntu bash java ..

  • The Overflow Blog
  • How to prevent your new chatbot from giving away company secrets
  • Introducing Staging Ground: The private space to get feedback on questions...
  • Featured on Meta
  • Testing a new version of Stack Overflow Jobs

Hot Network Questions

  • Culture of conferences and registration fees
  • What is the Alberto Moravia Prize?
  • Post Apocalyptic Military
  • Is it legal to deposit a check that says pay to the order of cash
  • How did ALT + F4 become the close shortcut?
  • Why did my 50µm gold wire vanish when I tried to tin it?
  • When to write a custom exception handler?
  • Why do airplanes sometimes turn more than 180 degrees after takeoff?
  • Is xz on brew on Ubuntu vulnerable?
  • Can't install Reaper on Ubuntu 24
  • Can 14th level Artificers attune / use sub-race specific magic items?
  • Who has the final say in making revisions to a manuscript after it has been returned by reviewers?
  • Is this an image of an astronomical observatory? If not, what's behind these domes?
  • Doubt in type II supernovae
  • Obvious wrongness of Aristotle
  • How much support does a ground offensive in Lebanon have among the Israeli public?
  • How can I start using Git in a project that is already underway?
  • Is bike tyre pressure info deliberately hard to read?
  • How does Death Ward interact with Band of Loyalty?
  • Isekai/reincarnation manga where the main character is transported inside a game with his sister
  • What was the nature of Yasir Arafat's difficulties in Arabic?
  • Transform sequence into ragged list
  • How to create the guide-words in a dictionary
  • Why is an article often used with (the) Rubik's cube, although other "name+'s" constructions never use one? [EDIT: depends on context, s. description]

export java_home inconsistent type for assignment

Select Your Language

  • Single-page

Language and Page Formatting Options

Chapter 5. configuring the java_home environment variable on rhel.

Some applications require you to set the JAVA_HOME environment variable so that they can find the Red Hat build of OpenJDK installation.

Prerequisites

  • You know where you installed Red Hat build of OpenJDK on your system. For example, /opt/jdk/11 .

Set the value of JAVA_HOME .

Verify that JAVA_HOME is set correctly.

You can make the value of JAVA_HOME persistent by exporting the environment variable in ~/.bashrc for single users or /etc/bashrc for system-wide settings. Persistent means that if you close your terminal or reboot your computer, you do not need to reset a value for the JAVA_HOME environment variable.

The following example demonstrates using a text editor to enter commands for exporting JAVA_HOME in ~/.bashrc for a single user:

Additional resources

  • Be aware of the exact meaning of JAVA_HOME . For more information, see Changes/Decouple system java setting from java command setting .

Quick Links

  • Subscriptions
  • Support Cases
  • Customer Service
  • Product Documentation
  • Contact Customer Portal
  • Customer Portal FAQ
  • Log-in Assistance
  • Trust Red Hat
  • Browser Support Policy
  • Accessibility
  • Awards and Recognition

Related Sites

  • developers.redhat.com
  • connect.redhat.com
  • cloud.redhat.com

Systems Status

  • Red Hat Subscription Value
  • About Red Hat
  • Red Hat Jobs

Red Hat legal and privacy links

  • Contact Red Hat
  • Red Hat Blog
  • Diversity, equity, and inclusion
  • Cool Stuff Store
  • Red Hat Summit
  • Privacy statement
  • Terms of use
  • All policies and guidelines
  • Digital accessibility

How to set JAVA_HOME environment variable on Windows 10

error java command

Here, the home of JDK is under C:\Program Files\Java\jdk1.80_201 . The version number may vary, depending on the JDK you installed.

start menu open system environment variable dialog

The System Properties dialog appears, click the button Environment Variables .

System properties dialog

Then you will see this dialog:

Environment Variables dialog

  • How to set environment variables for Java using command line
  • How to write, compile and run a hello world Java program for beginners
  • What are JVM, JRE and JDK
  • How to check Java version

About the Author:

export java_home inconsistent type for assignment

Add comment

   

Notify me of follow-up comments

Comments  

Stack Exchange Network

Stack Exchange network consists of 183 Q&A communities including Stack Overflow , the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

How to set JAVA_HOME for Java?

I've installed a version of Java. How can we set the $JAVA_HOME environment variable correctly?

kiri's user avatar

4 Answers 4

You can set your JAVA_HOME in /etc/profile as Petronilla Escarabajo suggests. But the preferred location for JAVA_HOME or any system variable is /etc/environment .

Open /etc/environment in any text editor like nano or gedit and add the following line:

(java path could be different)

Use source to load the variables, by running this command:

Then check the variable, by running this command:

Usually most linux systems source /etc/environment by default. If your system doesn't do that add the following line to ~/.bashrc (Thanks @pje)

Zanna's user avatar

  • 2 When i tried to run Android Studio (that has IntelliJ IDEA as a base), i had an error message very similar to @advocate's: "'tools.jar' seems to be not in Android Studio classpath." After fiddling a lot with JAVA_HOME without success, i decided to take a look at studio.sh, the shellscript that starts Android Studio. As a wild guess, i set JDK_HOME to the same value expected for JAVA_HOME, and voila! It installed without great problems. –  Hilton Fernandes Mar 7, 2015 at 23:20
  • 6 For those doing software development, don't put your JAVA_HOME in /etc/environment unless you want to reboot everytime you switch JDK versions. –  Dave Sep 20, 2016 at 19:03
  • 3 This is a temporary solution, as others pointed out. No one would want to run source every time they restart their bash. –  yuranos Feb 19, 2017 at 21:49
  • 7 As others have pointed out, this doesn't stick between terminal sessions. What I did to address this is just added the line source /etc/environment to the top of my bash config file ~/.bashrc so that it loads all my environment settings on startup. Working for me so far. –  pje Mar 11, 2017 at 22:31
  • 2 @sedulam I updated the answer –  Manula Waidyanatha Apr 20, 2017 at 6:20

To set JAVA_HOME environment variable, do the following:

  • Launch Terminal by pressing Ctrl + Alt + T on your keyboard.
  • Enter the following command: $ gksudo gedit /etc/environment
  • Depending on where you installed your Java, you will need to provide the full path. For this example, I installed Oracle JDK 7 in the /usr/lib/jvm/java-7-oracle directory. Scroll to the end of the file and enter the following: JAVA_HOME=/usr/lib/jvm/java-7-oracle export JAVA_HOME
  • Save your file and exit gedit .
  • Lastly, reload the system PATH with the following command: $ . /etc/environment

The above method will save you the hassle in having to run the commands every time you log in to your computer.

Petronilla Escarabajo's user avatar

  • 7 How does . /etc/environment work? –  Sudip Bhandari Sep 13, 2016 at 13:36
  • 1 Is the addition of the export command necessary in the /etc/environment ? –  pkaramol Nov 23, 2016 at 10:01
  • @pkaramol I've had to add export JAVA_HOME on 16.04LTS to make it load at startup. –  adeen-s Jan 20, 2017 at 6:20
  • 4 @adeen-s You added export to a line in /etc/environment and it helped? That file contains variable definitions parsed as = -delimited name-value pairs; its contents are not executed as commands. (See man pam_env .) So unless you're separately treating the file as though it were a script (such as by passing /etc/environment to bash's . / source builtin), I wouldn't expect that to work. –  Eliah Kagan Aug 17, 2017 at 16:02
  • 1 > How does . /etc/environment work? -- . (dot) loads commands from a file askubuntu.com/a/232938/189965 –  Roman Bekkiev Sep 22, 2018 at 7:32

If you do not know the path and you only have openJDK installed, you can type update-alternatives --config java and you should find the path. To set the variable you can write JAVA_HOME=<PATH> followed by export JAVA_HOME . Notice there's no space when declaring the variable. To check if the variable is stored you simply type echo $JAVA_HOME to verify.

Erro's user avatar

  • 1 This seems like it would be static. If I remove openjdk-7 and install openjdk-9, won't the JAVA_HOME then point to the wrong place? How can it be made dynamic? –  DavidJ Jul 20, 2016 at 18:49
  • 3 By you manually changing it. Once again, YOU are the way it becomes dynamic.... –  Dave Sep 20, 2016 at 19:04
  • What @HDave means is that In certain cases, you may want JAVA_HOME to point to a specific java version, so making the update of JAVA_HOME dynamic may not be what you want. –  Maciej Oct 9, 2016 at 15:31
  • i like this answer. I tested with echo and see my path. However, I am confused why I am still getting JAVA_HOME environment variable is not set when I run mvn -version –  Winnemucca Apr 11, 2017 at 22:19
  • 3 I wrote this answer back when I was more ignorant. Setting the variable as described will only affect your current terminal session, and will not be persisted. The correct way is to run update-alternatives --install <link> <name> <target> <priority> for example: update-alternatives --install /usr/bin/java java /usr/lib/jvm/default-runtime/bin/java 1 –  Erro May 14, 2017 at 12:26

This is the best option if you always want to use the latest one installed. Nowadays (Ubuntu 23.10) you should probably have it installed through apt like:

In this case, you should find it at /usr/lib/jvm/default-java . It's a symlink that points to whichever the current JVM is on the same folder. So, just run this to add the environment as a separate file:

Add this line and save:

Then reboot or login again, or source /etc/environment.d/90java.conf to load it on the current shell.

geekley's user avatar

You must log in to answer this question.

Not the answer you're looking for browse other questions tagged java ..

  • The Overflow Blog
  • How to prevent your new chatbot from giving away company secrets
  • Introducing Staging Ground: The private space to get feedback on questions...
  • Featured on Meta
  • Testing a new version of Stack Overflow Jobs

Hot Network Questions

  • How to create the guide-words in a dictionary
  • Would mining asteroids cause meteorites
  • I see rainbow effect on the borders of objects and text, adjusting ClearType or driver reinstall doesn't resolve the issue
  • Is it a theorem of ZF that a non-empty countable Cartesian product of finite non-singleton sets has the cardinality of the continuum?
  • Footprints in the Snow
  • Transform sequence into ragged list
  • How much support does a ground offensive in Lebanon have among the Israeli public?
  • What math object is the wire star on Will Hunting's prof's desk?
  • Leaders and Rulers
  • Why raise livestock only in newer planetary settlements?
  • How does Death Ward interact with Band of Loyalty?
  • Do you have an expression saying "when you are very hungry, bread is also delicious for you" or similar one?
  • Explain to a non-physicist what goes wrong when trying to quantize gravity
  • Is this an image of an astronomical observatory? If not, what's behind these domes?
  • Can campaign promises be enforced by a contract, or has it ever happened they were?
  • A story about a boy with a fever who falls in the creek and is saved by an angel and grows up to be Hitler
  • What was the nature of Yasir Arafat's difficulties in Arabic?
  • Trouble with understanding classifying groups with semi direct products
  • Writing Chidushei Torah Immediately
  • GMC Canyon Transmission Change
  • How to make an Equilateral Triangle Grid with Geometry Nodes?
  • Can a Kerr black hole become super-extremal?
  • Is xz on brew on Ubuntu vulnerable?
  • How would artificial gravity panels affect spaceship design?

export java_home inconsistent type for assignment

It's FOSS

Fixing "zsh: bad assignment" error in Linux

Abhishek Prakash

The other day I was trying to create an alias in Linux for repetitive commands. An alias is a name that is translated as another name or command (or a set of commands).

So, I tried to create the alias in the following manner:

And it threw me the following error:

If you are a regular user of the Linux command line, you must have identified the error on the previous command. But I was preoccupied with my program in C++ and I did not notice the obvious error here.

In fact, I thought it to be an error with the way I used the combination of error for the alias. So, I fiddled for a couple of minutes and just to make sure what I was doing wrong, tried this command:

Now, I was certain that there was no error with the commands this time but I git the same result as above:

And that’s when I realized my mistake. You see, I have been working a lot with C++ and was following the standard of using spaces before and after the assignment operator (=). And that is what I used here as well. And shell does not like the wastage of “space”.

I removed the extra white spaces before and after the = and voilà! There it worked like a charm.

In fact, the same error can be encountered with the export command as well or any other variable assignments in the shell. There should not be spaces before and after equals sign.

This taught me a lesson to not waste white space while dealing with shell scripts and Linux commands. It’s not the same as writing programs in other languages.

I would add this tiny learning lesson to my list of things to know about the Linux terminal.

export java_home inconsistent type for assignment

I hope you would not have to waste your time with this problem if you mind those spaces before and after the equals sign.

Abhishek Prakash

Created It's FOSS 11 years ago to share my Linux adventures. Have a Master's degree in Engineering and years of IT industry experience. Huge fan of Agatha Christie detective mysteries 🕵️‍♂️

How To Fix Ubuntu Update Error: Problem With MergeList

How to fix "repository is not valid yet" error in ubuntu linux, how to use nightlight feature in linux mint to save your eyes at night, fixing 'shell script opening in text editor' in ubuntu and other linux, handling 'cannot refresh snap-store' error in ubuntu 24.04, become a better linux user.

With the FOSS Weekly Newsletter, you learn useful Linux tips, discover applications, explore new distros and stay updated with the latest from Linux world

It's FOSS

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to It's FOSS.

Your link has expired.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.

export java_home inconsistent type for assignment

JAVA_HOME: inconsistent type for assignment, why this issue occurs after updating the JAVA_HOME in zshrc and how to fix it?

I am switching between java 8 and java 11 for some reason recently after updating the JAVA_HOME, I see a problem in IntelliJ IDEA for my Gradle project. so I am trying from scratch to setup java in Mac. but stuck with this inconsistent issue.

Process 'command '/Applications/IntelliJ IDEA CE.app/Contents/jbr/Contents/Home/bin/java'' finished with non-zero exit value 1
  • Related Question
  • Related Blog
  • Related Tutorials

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:[email protected].

  • environment-variables
  • command-line

Navigation Menu

Search code, repositories, users, issues, pull requests..., provide feedback.

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly.

To see all available qualifiers, see our documentation .

  • Notifications You must be signed in to change notification settings

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

Project does not build due to build path being incomplete #1595

@bryanmylee

bryanmylee commented Aug 26, 2020 • edited

  • 👍 8 reactions
  • 👀 1 reaction

bryanmylee commented Aug 26, 2020

Sorry, something went wrong.

@fbricon

fbricon commented Aug 26, 2020

@snjeza

snjeza commented Aug 26, 2020

  • 👍 6 reactions
  • ❤️ 2 reactions

bryanmylee commented Aug 27, 2020

Snjeza commented aug 27, 2020, bryanmylee commented aug 29, 2020.

@Rupert-117

Rupert-117 commented Sep 14, 2020

@marcelweigle

marcelweigle commented Jan 15, 2021

  • 👍 48 reactions
  • 🎉 3 reactions
  • ❤️ 26 reactions

@HaraldKi

HaraldKi commented Jan 31, 2021 • edited

@bibhas2

bibhas2 commented Apr 14, 2021 • edited

  • 👍 3 reactions
  • ❤️ 1 reaction

@zhanghuanhuanzhang

zhanghuanhuanzhang commented Feb 8, 2022

@cowlike

cowlike commented Feb 19, 2022 • edited

  • 👍 1 reaction

@luangong

luangong commented Apr 28, 2022

  • ❤️ 11 reactions

@SeFeX

SeFeX commented May 3, 2022

@miqueiaspcoelho

miqueiaspcoelho commented Dec 9, 2022

@charafsalmi

charafsalmi commented Jan 30, 2023 • edited

  • 🎉 2 reactions

@testforstephen

ghost commented Sep 13, 2023

  • ❤️ 5 reactions

@C-Vilen

C-Vilen commented Sep 13, 2023

@Ferdous123

Ferdous123 commented Sep 14, 2023

@tonyoruovo

tonyoruovo commented Dec 6, 2023

No branches or pull requests

@fbricon

IMAGES

  1. How to Set JAVA_HOME and PATH variables for Ubuntu

    export java_home inconsistent type for assignment

  2. [Solved] How to solve "The hierarchy of the type is

    export java_home inconsistent type for assignment

  3. Export via processing-java is broken and has inconsistent design

    export java_home inconsistent type for assignment

  4. Export Java Project in Eclipse

    export java_home inconsistent type for assignment

  5. How to Set JAVA_HOME Linux

    export java_home inconsistent type for assignment

  6. Set JAVA_HOME on CentOS / RHEL / Fedora

    export java_home inconsistent type for assignment

VIDEO

  1. Export Java Application As Setup With Netbeans

  2. iDempiere 3.1 Installation in Linux (Ubuntu / Elementary OS)

  3. Instalação Android Studio e varável de ambiente Compose multiplatform KMP Curso Aula 01

  4. 🔴 Types of Error in Java || ICSE || Java

  5. 06 Python API2 2024 Fonctions, Récursivité

  6. Example of an inconsistent system of equations

COMMENTS

  1. bash

    I got this when changing a value for JAVA17_HOME. Doing. unset JAVA17_HOME and then setting it again worked. Not the original problem, which was answered, but may help people who land here while searching.

  2. Incorrect value of environment variable java_home

    You need to run: source /etc/environment. so that the variables declared on the /etc/environment are available on the current shell and you will get the value of the variable set from the current shell. To make the variable available to all child processes of the shell, export it after source -ing: export JAVA_HOME.

  3. How to Set JAVA_HOME / PATH variables Under Linux Bash Profile

    Login to your account and open .bash_profile file $ vi ~/.bash_profile Set JAVA_HOME as follows using syntax export JAVA_HOME=<path-to-java>. If your path is set to /usr/java ... Just logout and login back to see new changes. Alternatively, type the following command to activate the new path settings immediately: $ source ~/.bash_profile OR ...

  4. JAVA_HOME is not set correctly after adding and appending to PATH

    Stack Exchange Network. Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.. Visit Stack Exchange

  5. How to set JAVA_HOME on Linux

    Environment variables can be set up in three different types: Local Environment variables: Bind to a specific session. User Environment variables: Bind to a specific user. System Environment variables: Bind to system-wide. 1. Set JAVA_HOME with export: Using export command we can set the JAVA_HOME, but as we discussed, this is volatile ...

  6. How can I expose JAVA_HOME to applications running under X and/or Gnome?

    According to Ubuntu's Wiki on Environment Variables either in ~/.pam_environment or in /etc/environment, depending on what you want it for all users, or just your user.. Session-wide environment variables. Environment variable settings that should affect just a particular user (rather then the system as a whole) should be set into:

  7. variable

    Tour Start here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site

  8. environment variables

    In zsh, Command Substitution result was performed word splitting if was not enclosed in double quotes. So if your command substitution result contain any whitespace, tab, or newline, the export command will be broken into parts: $ export a=$(echo 1 -2) export: not valid in this context: -2. You need to double quote command substitution to make ...

  9. Chapter 5. Configuring the JAVA_HOME environment variable on RHEL

    You can make the value of JAVA_HOME persistent by exporting the environment variable in ~/.bashrc for single users or /etc/bashrc for system-wide settings. Persistent means that if you close your terminal or reboot your computer, you do not need to reset a value for the JAVA_HOME environment variable.. The following example demonstrates using a text editor to enter commands for exporting JAVA ...

  10. How to set JAVA_HOME environment variable on Windows 10

    Then you will see this dialog: 3.Create the JAVA_HOME environment variable by clicking the New button at the bottom. In the New System Variable form, enter the name and value as follows: Click OK, and you will see the JAVA_HOME variable is added to the list. 4.Update the PATH system variable. In the Environment Variables dialog, select the Path ...

  11. How to set JAVA_HOME for Java?

    To set JAVA_HOME environment variable, do the following: Launch Terminal by pressing Ctrl + Alt + T on your keyboard. Enter the following command: $ gksudo gedit /etc/environment. Depending on where you installed your Java, you will need to provide the full path.

  12. What is the correct way to export JAVA_HOME? : r/javahelp

    Archived post. New comments cannot be posted and votes cannot be cast.

  13. [Solved] "zsh: bad assignment" error in Linux

    An alias is a name that is translated as another name or command (or a set of commands). So, I tried to create the alias in the following manner: alias my_short_command = "command 1; command 2 && command 3; command 4". And it threw me the following error: zsh: bad assignment. If you are a regular user of the Linux command line, you must have ...

  14. java

    I am switching between java 8 and java 11 for some reason recently after updating the JAVA_HOME , I see a problem in IntelliJ IDEA for my Gradle project. so I am trying from scratch to setup java in Mac. but stuck with this inconsistent issue. Process 'command '/Applications/IntelliJ IDEA CE.app/C

  15. Unwanted output when source ~/.zshrc #125

    You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window.

  16. Project does not build due to build path being incomplete #1595

    None of my Java projects are being built properly by the language server. All my projects are failing, even previously working projects. Fundamentally, I'm getting JRE errors such as The type java.lang.Object cannot be resolved.It is indirectly referenced from required .class files.

  17. How to downgrade Java from 9 to 8 on a MACOS. Eclipse is not running

    How to downgrade Java from 9 to 8 on a macOS Sierra 10.12.6(16G29) . I tried removing the Java plugin and installed Java 8, however the Java and javac version shows 9 in terminal, but In system