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 Stack Overflow is partnering with Google to encourage socially...
  • Your whole repo fits in the context window
  • Featured on Meta
  • Our partnership with Google and commitment to socially responsible AI
  • Shifting the data dump schedule: A proposal

Hot Network Questions

  • What is the advantage of using a particular RK Scheme?
  • Travelling on passport that has 1.5 months left
  • the joke in muppet sketch: the comedian's a bear
  • Wrong result for simple real-valued integral (spurious imaginary part)
  • Melissa's Numbers
  • Copy a folder name into the name of its files
  • Should the evidence of OBEs and NDEs increase our epistemic probability of non-physicalist views of consciousness?
  • Who pays for the damages caused by the government attempting to enforce a preempted or unconstitutional law?
  • Seeking advice on getting a wild bird out an open window or door, alone, with no help. (Location, Virginia)
  • Quantum Superposition and the Possibility of Free Will
  • Shunting yard calculator in C
  • Ex-advisor wants to publish my work in a journal I don't like
  • Safe, easy way to tap into taut NM cable in wall?
  • Geometry Nodes: re-using a node group that includes main Group Input values
  • Is it possible, by monitoring the brightness of stars, to find a “copy of the Earth + Moon” near them?
  • Was the Holtzman Shield gas permeable?
  • Egypt hotel deliberately overcharged dollar payments and refunded the difference in cash. Why?
  • What is the origin of the simulacrum spell?
  • Apex Built-in Counter Class?
  • Can Fortnite Vbucks cards be used on any console?
  • To copy a file and preserve its comment
  • Why are supercritical airfoils not used in GA aircraft?
  • Deleting Software I Wrote Upon Leaving Employment of a Company
  • How can I motivate and deal with speculation?

export java_home inconsistent type for assignment

Select Your Language

Infrastructure and management.

  • Red Hat Enterprise Linux
  • Red Hat Satellite
  • Red Hat Subscription Management
  • Red Hat Insights
  • Red Hat Ansible Automation Platform

Cloud Computing

  • Red Hat OpenShift
  • Red Hat OpenStack Platform
  • Red Hat OpenShift Container Platform
  • Red Hat OpenShift AI
  • Red Hat OpenShift Dedicated
  • Red Hat Advanced Cluster Security for Kubernetes
  • Red Hat Advanced Cluster Management for Kubernetes
  • Red Hat Quay
  • OpenShift Dev Spaces
  • Red Hat OpenShift Service on AWS
  • Red Hat Gluster Storage
  • Red Hat Hyperconverged Infrastructure
  • Red Hat Ceph Storage
  • Red Hat OpenShift Data Foundation
  • Red Hat Runtimes
  • Red Hat JBoss Enterprise Application Platform
  • Red Hat Data Grid
  • Red Hat JBoss Web Server
  • Red Hat build of Keycloak
  • Red Hat support for Spring Boot
  • Red Hat build of Node.js
  • Red Hat build of Quarkus

Integration and Automation

  • Red Hat Application Foundations
  • Red Hat Fuse
  • Red Hat AMQ
  • Red Hat 3scale API Management
  • 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

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 Stack Overflow is partnering with Google to encourage socially...
  • Your whole repo fits in the context window
  • Featured on Meta
  • Our partnership with Google and commitment to socially responsible AI
  • Shifting the data dump schedule: A proposal
  • AI-generated content is not permitted on Ask Ubuntu
  • Goodbye Gunnar Hjalmarsson 1958.10.06 - 2023.12.20

Hot Network Questions

  • How to make all the fontawesome5 icons in a document small?
  • Why would a warrior tribe be dependant on a pacifist tribe?
  • Why does prompt engineering work, since prompt engineering questions don't appear as training data?
  • Is there equivalent for "I am starving to death" in German?
  • Safe, easy way to tap into taut NM cable in wall?
  • Is it possible, by monitoring the brightness of stars, to find a “copy of the Earth + Moon” near them?
  • PTIJ: Why are we fixated on our voices?
  • What is the debris that occasionally flew off Starship during its coasting phase today?
  • Quantum Superposition and the Possibility of Free Will
  • What is the difference between "pretty" and "handsome" in this context?
  • PTIJ: Are we allowed to eat talking animals?
  • What is this large device labelled 'Telefunken Datenspeicher' and how does it work?
  • Linking quaver and semiquaver beams over a rest with LilyPond
  • Will air in a shockwave flow outwards?
  • Egypt hotel deliberately overcharged dollar payments and refunded the difference in cash. Why?
  • Installing mysql-community-devel on RHEL9, "Errors during downloading metadata for repository 'mysql80-community'"
  • why or when do we use the general form of conic sections?
  • Is my queue table implementation race condition safe?
  • What do "fünf Tage Dicken" and "fünf Tage Kahn" mean in All Quiet on the Western Front?
  • What would an “unmanipulated election” look like?
  • Command for Multiplying Integers
  • To copy a file and preserve its comment
  • Can Fortnite Vbucks cards be used on any console?
  • I do not understand behavior of current in 74HC4066

export java_home inconsistent type for assignment

onlinetutorialspoint Logo

How to set JAVA_HOME on Linux

We can set JAVA_HOME on Linux in different ways. One of the prominent ways is to set the JAVA_HOME using an environment variable.

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 – as soon as we leave the terminal session, this setting will go away.

1.1 Setting PATH:

2. set java_home environment:.

We can permanently set the JAVA_HOME using /etc/environment file. This will be applied to system-level.

Add the below lines to add the JAVA_HOME

2.1 Apply the changes:

Apply the environment variables by using the source command.

References:

  • How to set JAVA_HOME on windows

Happy Learning 🙂

Related Posts

  • Java 8 – How to set JAVA_HOME on Windows10
  • How to install Java on Mac OS
  • How to restart MsSQL server on Linux
  • How to find Linux RHEL version ? OS and Kernel Version ?
  • Python – How to read environment variables ?
  • How to install Maven on windows 7 command line
  • How to install Maven in Mac OSX
  • How to install Maven on Windows10
  • Linux vi commands list
  • Difference between Path vs Classpath in Java
  • How set AWS Access Keys in Windows or Mac Environment
  • How to Install Ant on Windows 10
  • C How to Pass Arrays to Functions
  • Jdk Jre Jvm and differences
  • C Local and Global Variables

Share a word.

About the author: chandrashekhar.

' src=

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

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

Unwanted output when source ~/.zshrc #125

@SunsetYe66

SunsetYe66 commented Dec 28, 2021

  • 👍 1 reaction

@jayeshathila

jayeshathila commented Jan 2, 2022

Sorry, something went wrong.

@sweetgiorni

Successfully merging a pull request may close this issue.

@jayeshathila

  • View account
  • View requests

Jira Software

Project and issue tracking

Jira Service Management

Service management and customer support

Jira Work Management

Manage any business project

Document collaboration

Git code management

Documentation

Usage and admin help

Answers, support, and inspiration

System Status

Cloud services health

Suggestions and bugs

Feature suggestions and bug reports

Marketplace

Product apps

Billing and licensing

Frequently asked questions

  • Log in to account
  • Contact support
  • Training & Certification
  • Cloud Migration Center
  • GDPR guides
  • Enterprise services
  • Atlassian partners
  • User groups
  • Automation for Jira
  • Atlassian.com
  • View in Confluence
  • Manage Viewport
  • Space Directory
  • People Directory
  • Setting JAVA_HOME

Supported Platforms

On this page, related content.

  • No related content found

Still need help?

The Atlassian Community is here for you.

Ask the community

Once you have installed the JDK (see Supported Platforms ), you need to set the JAVA_HOME environment variable.

To set the JAVA_HOME environment variable on Windows

  • Right click on the ' My Computer ' icon on your desktop and select ' Properties '.
  • Click the ' Advanced ' tab.
  • Click the ' Environment Variables ' button.
  • Click ' New '.
  • In the ' Variable name ' field, enter 'JAVA_HOME'.
  • In the ' Variable value ' field, enter the directory (including its full path) where you installed the JDK.
  • Restart the computer.

To set the JAVA_HOME environment variable on 'nix based systems

There are many ways you can do it on 'nix based systems (including Mac OS X). Here are two:

For your current user,

  • Open up a shell / terminal window
  • vi ~/.profile  (replace vi with your favorite text editor)
  • Add  export JAVA_HOME=/path/to/java/home/dir  on its own line at the end of the file
  • Add  export PATH=$JAVA_HOME/bin:$PATH  on its own line immediately after
  • Save, and restart your shell
  • Running  java -version  should give you the desired results

For all users in the system,

  • vi /etc/profile  (replace vi with your favorite text editor)

If you are using a GUI, you may not need to open up the shell. Instead, you might be able to open the file directly in a graphical text editor.

RELATED TOPICS

  • MS SQL Server
  • HSQLDB for CrowdID
  • MS SQL Server for CrowdID
  • MySQL for CrowdID
  • Oracle for CrowdID
  • PostgreSQL for CrowdID
  • Installing Crowd WAR Distribution
  • Installing CrowdID WAR Distribution
  • Specifying your Crowd Home Directory
  • Troubleshooting your Configuration on Setup
  • The crowd.properties file
  • Changing the Port that Crowd uses
  • Configuring Crowd to Work with SSL
  • Specifying Startup Order of Windows Services
  • Changing the User for the Crowd Windows Service
  • Removing the Crowd Windows Service
  • Troubleshooting Crowd as a Windows Service
  • Setting Crowd to Start Automatically on Mac OS X
  • Setting Crowd to Run Automatically and Use an Unprivileged System User on UNIX

Was this helpful?

IMAGES

  1. How To Export And Import Java Project In Eclipse

    export java_home inconsistent type for assignment

  2. How to set JAVA_HOME in Windows 10

    export java_home inconsistent type for assignment

  3. How to export packages from Java 9 module

    export java_home inconsistent type for assignment

  4. How to Set JAVA_HOME Linux

    export java_home inconsistent type for assignment

  5. How to Install Java on macOS? Export JAVA_HOME Env variable in .bash

    export java_home inconsistent type for assignment

  6. Set JAVA_HOME on CentOS / RHEL / Fedora

    export java_home inconsistent type for assignment

VIDEO

  1. How to export certificate from java keystore #short

  2. Set JAVA_HOME on Ubuntu 16.04

  3. JAVA FILE HANDLING ~ PART

  4. JAVA FILE HANDLING ~ PART

  5. JAVA FILE HANDLING ~ PART

  6. java Data Type's

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. JAVA_HOME is not set correctly after adding and appending to PATH

    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

  4. 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 ...

  5. How to Set JAVA_HOME Path in Ubuntu 20.04 and Ubuntu 22.04

    Set JAVA_HOME Path. All you have to do now is to set the "JAVA_HOME" and "PATH" environment variables, and then you are done. Enter the following commands to set your environment variables. Ensure that your environment variables point to a valid installation of JDK on your machine. For Ubuntu 18.04, the path is /usr/lib/jvm/java-8 ...

  6. 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 ...

  7. 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.

  8. Set JAVA_HOME on Windows 7, 8, 10, Mac OS X, Linux

    Windows 7. On the Desktop, right-click My Computer and select Properties. Under the Advanced tab, click Environment Variables. In the System variables section, click New (or User variables for single user setting). Set JAVA_HOME as the Variable name and the path to the JDK installation as the Variable value and click OK.

  9. JAVA_HOME not exported properly · Issue #188 · jenv/jenv

    Since shell wasn't restarted the JAVA_HOME remains initialized to the old 1.8 while jenv itself reports its current value 10 (extracted from the global/local .version files). From what I can deduce and the brief mention in the README docs: JAVA_HOME is set by the 'export' plugin at shell startup only. So behaviour is as designed and not a bug ...

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

    I just need a help to show me how to setup java path on Linux. How can I set JAVA_HOME and PATH variables for every user under my Linux system? ~/.bash_profile is a startup script which generally runs once. This particular file is used for commands which run when the normal user logs in. Common uses for .bash_profile are to set environment variables such as PATH, JAVA_HOME, to create aliases ...

  11. 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 ...

  12. 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.

  13. Setting JAVA_HOME

    To set the JAVA_HOME environment variable on Windows. Right click on the ' My Computer ' icon on your desktop and select ' Properties '. Click the ' Environment Variables ' button. Click ' New '. In the ' Variable name ' field, enter 'JAVA_HOME'. In the ' Variable value ' field, enter the directory (including its full path) where you installed ...

  14. Having JAVA_HOME inconsistency issue with maven

    It just overrides your settings. Another fix/workaround for that is to update symlink, in my case it was /usr/lib/jvm/java ⇒ /usr/java/jdk1.7.0_45. Try to look for java/bin text in all bash files. Hope you set the JAVA_HOME check if your JAVA_HOME is set using command.

  15. bash

    Remove the spaces from around = and make sure there are no spaces embedded in the value you want to assign to PATH. Wrap the entire right-hand side value in quotes ( "/Users/... ") if one of the paths you put there contain spaces. Share. Improve this answer.

  16. java

    Not blaming anything. Only accuses the code itself:"The hierarchy of the type BDIGenericGeneratorEvent is inconsistent". That means this class was not compiled with the version you have for a super class. The class exists in the imported package (Java Build Path / Projects), but as it was not imported the class.