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
  • Is GenAI the next dot-com bubble?
  • Featured on Meta
  • New Focus Styles & Updated Styling for Button Groups
  • Upcoming initiatives on Stack Overflow and across the Stack Exchange network
  • Google Cloud will be Sponsoring Super User SE

Hot Network Questions

  • Possible to dot your Is with hearts?
  • Protecting against malicious duplicate IDs in a distributed environment
  • Is it impossible to protect an API from data redistribution?
  • How can I fix my loose Towel Hanger that is sliding down and making the bar fall
  • 4,4,2,6,2,10,4,_ sequence from 4th grade packet
  • Why would two different sized bikes not arrive at the same time starting from rest on the same slope?
  • How do I change the page size for a pdf-file generated by plain-TeX?
  • Conservative cocompletion of categories of geometric shapes for homotopy theory
  • Once a congressional bill has become law, how is it noticed by and overseen within the executive branch?
  • What strategies can a fighter implement to shield the outer knee from injuries caused by opponents’ strikes?
  • Is there a standard which requires a high voltage warning label on a PCB?
  • Why is the aperture door of the Hubble Space Telescope so weirdly shaped?
  • PhD supervisor wants to assume my apartment lease and buy my improvements to the apartment when I move out
  • Can an undergraduate student be penalized for exceeding what is expected of a work?
  • What are advantages of plasma based weaponry in ship-to-ship combat
  • Why does the BRK instruction set the B flag?
  • How understandable is this statistical hypothesis?
  • Could a historic (1500- 1700 AD) bicycle stand rough terrain? If yes how?
  • Data Science undergrad degree isn't what I expected to be
  • Diode clipping question on output of opamp
  • Secular Ashkenazi marries Sephardia. Can house adopt sephardic customs (minhag avot doesn't apply to husband)?
  • What's the purpose of Wormskin Folios?
  • Why is home ownership so low in Switzerland?
  • Make a command robust (unbreakable)

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

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.

Cannot export variable thanks to a script with zsh

I have written a script export-zsh to set new variables in zsh

Errors occur if I run it

When I execute each command individually, it lead to no errors:

when I run source ~/.zshrc , there are no errors, so I don't think it should be directly related to my ~/.zshrc content but I give it below to be sure.

user123456's user avatar

You script is executed by Bash. Reading your .zshrc with Bash doesn't work but gets you errors for all the Zsh specific stuff.

Your script runs in its own subshell. As settings, environment variables and such are not exported back to the calling shell ascript will not work here. Use a function instead and put it in your .zshrc :

Florian Diesch's user avatar

You must log in to answer this question.

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

  • The Overflow Blog
  • Is GenAI the next dot-com bubble?
  • Featured on Meta
  • New Focus Styles & Updated Styling for Button Groups
  • Upcoming initiatives on Stack Overflow and across the Stack Exchange network
  • AI-generated content is not permitted on Ask Ubuntu
  • Let's organize some chat workshops

Hot Network Questions

  • How can a senior finance building a home with no current credit score but good equity in current home?
  • How many lands in total can be put into play with Map the Frontier?
  • Is it a cartesian product?
  • What is this usage of 出た?
  • Conservative cocompletion of categories of geometric shapes for homotopy theory
  • `\IfSubStr` in a tikz style
  • Why do GCC and Clang pop on both branches instead of only once? (Factoring parts of the epilogue out of tail-duplication)
  • Why has the number of Germans in Kazakhstan begun to increase?
  • How to plan a trail route?
  • How do flyback converters operating in CCM regulate their output?
  • Protecting against malicious duplicate IDs in a distributed environment
  • Can I say "keep your head tipping backwards for 2 minutes" to mean to keep the head still and in a state that it is fixed at a tipping position?
  • Evaluate the binomial integral
  • Latin minimal pairs, distinguished only by the length of the vowel in an unstressed non-last syllable
  • What are "the feelings of an Emma towards her Henry"?
  • Make a command robust (unbreakable)
  • Jawohl answer when someone knocks at the door
  • What would be the grounds for the US Chamber of Commerce to sue the FTC over its new rule concerning noncompetes?
  • Apex (de)serialize JSON with Map<String, Object> properties
  • is Batman's utility belt ever missing something he needs?
  • Spacecraft rescued when they transmitted Morse code
  • PhD supervisor wants to assume my apartment lease and buy my improvements to the apartment when I move out
  • Where can I get an earth-centric map of space?
  • Why don't they use guns or lasers on Arrakis?

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, enabling bluetooth on arch linux, it's foss.

Making You a Better Linux User

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.

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.

Tomcat service does not see $JAVA_HOME

I'm trying to setup a Tomcat service with Systemd on CentOS 7.

I've installed Oracle Java 1.8u74 to /usr/java/jdk1.8.0_74 and set the environment variable $JAVA_HOME at boot like so:

When I login to the system I can run echo $JAVA_HOME and see the correct path. I have installed Tomcat and the tomcat.service file has the following:

The problem is that if I omit the line that reads Environment=JAVA_HOME=/usr/java/jdk1.8.0_74 , Tomcat does not find $JAVA_HOME, but I expect it to find $JAVA_HOME because it is set in /etc/profile.d/setenv.sh .

My questions

  • Is it not found due to boot sequence (i.e. setenv.sh runs after the Systemd start)?
  • Did I put setenv.sh in the wrong place?
  • What's the best way to handle this?
  • environment-variables

slm's user avatar

This is the expected behavior with systemd.

To understand what the environment that systemd services run in, you can refer to man systemd.exec , specifically the section ENVIRONMENT VARIABLES IN SPAWNED PROCESSES . As it says, only very few variables are set, and you have to set anything else yourself.

It just happens that the files in /etc/profile.d are sourced by interactive shells, which is why you can see the variable when you log in. What you have done is exactly what the tutorial recommends, so you can just stick to it. If you are worried that a Java upgrade would break your unit file, you can make a symlink to your java installation, or even source the file at startup:

I would personally stick with what you have already.

chutz's user avatar

You must log in to answer this question.

Not the answer you're looking for browse other questions tagged linux java centos7 systemd environment-variables ..

  • The Overflow Blog
  • Is GenAI the next dot-com bubble?
  • Featured on Meta
  • New Focus Styles & Updated Styling for Button Groups
  • Upcoming initiatives on Stack Overflow and across the Stack Exchange network

Hot Network Questions

  • Does fully frozen food (bread) give off any moisture?
  • Why has the number of Germans in Kazakhstan begun to increase?
  • Why don't they use guns or lasers on Arrakis?
  • Is putting a silly name on a diploma a bad idea?
  • Can the Sunburst spell kill a vampire?
  • Evaluate the binomial integral
  • Must there be a proper class of Reinhardt cardinals if there is a Reinhardt cardinal?
  • Why is the aperture door of the Hubble Space Telescope so weirdly shaped?
  • Can an undergraduate student be penalized for exceeding what is expected of a work?
  • Booking hotel relative to local or home timezone
  • What strategies can a fighter implement to shield the outer knee from injuries caused by opponents’ strikes?
  • A genius Margonon!
  • How do I know how many breakers I can put into my main panel?
  • Conservative cocompletion of categories of geometric shapes for homotopy theory
  • What copyleft license could I use for a program that depends on non-free libraries?
  • Can I say "keep your head tipping backwards for 2 minutes" to mean to keep the head still and in a state that it is fixed at a tipping position?
  • Jawohl answer when someone knocks at the door
  • Latin minimal pairs, distinguished only by the length of the vowel in an unstressed non-last syllable
  • Why is "creating jobs" seen as good and "destroying jobs" seen as bad, even when there are major labour shortages?
  • A right-angled triangle has sides of integer length. Its area (in square metres) is twice its perimeter (in metres). What are the lengths of the sides
  • Model and implication of bidirectional time
  • Why does this "hot chassis" TV have the inputs isolated by an active circuit instead of just a capacitor?
  • How would a predator adapt to prey on sapient species?
  • Prime and Composite 6x6 Chocolate Banana

export java_home inconsistent type for assignment

  • 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?

How to Set Up the JAVA_HOME Variable on Windows 11

Get Java working as it should with this JAVA_HOME guide for Windows 11.

Are Java-based applications not working or throwing errors on your Windows PC? If so, it's likely that the JAVA_HOME environment variable is not set up correctly.

But what is the JAVA_HOME environment variable, and how can you set it up on Windows 11? Here's everything you need to know.

What Is the JAVA_HOME Environment Variable?

The JAVA_HOME environment variable is a system variable that points to the location where the Java Development Kit (JDK) is installed on your computer. The JDK is a software environment that allows Java-based applications to run on your computer without an issue.

Windows automatically sets the JAVA_HOME environment variable during the Java installation process. However, you will need to manually set it up if you have installed Java on your computer after the initial installation.

You can set up the JAVA_HOME environment variable using the below syntax:

For instance, if Java is installed in the directory C:\Program Files\Java\jdk-20, then you would set the JAVA_HOME environment variable as follows:

Now that you know briefly about the JAVA_HOME environment variable, let's check out how to set it up on Windows 11.

How to Set Up the JAVA_HOME Environment Variable by Editing the Advanced System Settings

Advanced system settings is a system configuration window that allows you to configure advanced settings on your Windows PC. You can use it to speed up your computer's performance , manage user profiles, change the default operating system, and much more. You can also use it to access and edit environment variables.

Here's how to use the Advanced system settings window to set up the JAVA_HOME variable:

  • Press the Win + I keys together to open Settings.
  • Choose System from the left sidebar and click About in the right pane.
  • Click New .
  • Click OK to save the changes.

You can now run Java programs without any issues on your Windows PC.

How to Set Up the JAVA_HOME Environment Variable Using the Command Prompt

If you are an advanced Windows user, you can use Command Prompt to set up the JAVA_HOME variable. Here's how to do it.

  • Press the Win key to open the Start Menu .
  • Type Command Prompt in the search bar and select Run as administrator from the right pane.

After that, close Command Prompt and restart your computer to save the changes.

How to Verify That the JAVA_HOME Environment Variable Is Set Up Correctly

After setting up the JAVA_HOME environment variable, you must verify that it is set up correctly on your computer. To do this, open Command Prompt window as an administrator (check out different ways to launch Command Prompt with administrative rights ), type the following command, and press Enter:

This will display the value of the JAVA_HOME environment variable on your computer, which is the root directory of the Java Development Kit (JDK).

You can also type the following command and press Enter. This will display the version of the Java compiler that is installed on your computer.

If either of these commands does not produce the expected output, you likely made a mistake in the setup process. In this case, go through the process again carefully to make sure that the JAVA_HOME environment variable is set up correctly.

Run Java Applications Without Any Difficulty on Windows

Running Java-based applications like Apache Tomcat on Windows is easy. However, if you see an error message or have any other problems running these applications, it's likely that the JAVA_HOME environment variable is not set correctly on your computer. Fortunately, you can quickly set up the JAVA_HOME environment variable using the steps above.

IMAGES

  1. How to set JAVA_HOME in Windows 10

    export java_home inconsistent type for assignment

  2. How To Export And Import Java Project In Eclipse

    export java_home inconsistent type for assignment

  3. How to set JAVA_HOME in macOS and Linux permanently

    export java_home inconsistent type for assignment

  4. How to export packages from Java 9 module

    export java_home inconsistent type for assignment

  5. How to Set JAVA_HOME Linux

    export java_home inconsistent type for assignment

  6. javascript

    export java_home inconsistent type for assignment

VIDEO

  1. Code Tic Tac Toe in Java

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

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

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

  5. Instance Variables

  6. How to install Java on macOS in less than 4 mins

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

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

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

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

    Open Search and type advanced system settings.; In the shown options, select the View advanced system settings link.; 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 then click OK.

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

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

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

  9. Cannot export variable thanks to a script with zsh

    You script is executed by Bash. Reading your .zshrc with Bash doesn't work but gets you errors for all the Zsh specific stuff.. Your script runs in its own subshell. As settings, environment variables and such are not exported back to the calling shell ascript will not work here.

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

  11. linux

    This is the expected behavior with systemd. To understand what the environment that systemd services run in, you can refer to man systemd.exec, specifically the section ENVIRONMENT VARIABLES IN SPAWNED PROCESSES.As it says, only very few variables are set, and you have to set anything else yourself.

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

  13. How to Set Up the JAVA_HOME Variable on Windows 11

    Press the Win + I keys together to open Settings. Choose System from the left sidebar and click About in the right pane. Click Advanced system settings . Click Environment Variables . Under System variables, click New . In the Variable name field, type JAVA_HOME and in the Variable value field, paste the copied address.

  14. bash

    Stack Overflow Public questions & answers; Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers; Talent Build your employer brand ; Advertising Reach developers & technologists worldwide; Labs The future of collective knowledge sharing; About the company

  15. Export assignment and exporting types in TypeScript ambient module

    export = config; You can use the imports like so: As a side note, you cannot use enums with an ambient module (the declare module 'config') because enums compile to a JS object and you can't add new object to a module you don't control. You can work around the issue by faking an enum with a union type: