What Is Java Used For On My Mac

What Is Java Used For On My Mac Rating: 5,0/5 5285 reviews

This is why it is popular as most Java developers do not need to worry if the system is Mac, Windows, Unix, etc. It is also used in some Smart.

While security is a common concern for Windows systems, most Mac users don’t have to worry about running an antivirusAre Antivirus Programs Necessary for Mac?Are Antivirus Programs Necessary for Mac?Read More or enabling a firewall on OS XDoes Your Mac Really Need A Firewall?Does Your Mac Really Need A Firewall?Dig through your Mac's settings and you'll find a firewall, turned off by default. Isn't that insecure? Why would Apple be so irresonsible?Read More. However, this doesn’t mean that Macs are impenetrable.

Java, a Web plug-in that was once ubiquitous but is dropping out of use in favor of HTML5, is still a valid security concern for Mac users. Chris explained why browser plug-ins are the worst security problems plaguing the Web todayBrowser Plugins - One of the Biggest Security Problems on the Web Today [Opinion]Browser Plugins - One of the Biggest Security Problems on the Web Today [Opinion]Web browsers have become much more secure and hardened against attack over the years. The big browser security problem these days is browser plugins. I don’t mean the extensions that you install in your browser..Read More, and Java fits into that category perfectly.

Let’s take a look at what Java is up to on OS X, and why you should chuck it to make your computer even more secure.

What is Java?

Unfortunately, Java often gets confused with JavaScript. Java itself comprises multiple items, so it’s easy to get them mixed up. Here’s a quick rundown:

  • JavaScript is a programming language that allows Web pages to be dynamic. Without JavaScript, the Web would consist of mainly boring text instead of interactive buttons, sliders, and fancy website integrations. Matt has elaborated further on JavaScriptWhat is JavaScript, And Can the Internet Exist Without It?What is JavaScript, And Can the Internet Exist Without It?JavaScript is one of those things many take for granted. Everybody uses it.Read More if you’re interested in learning about it.
  • Java is a programming language, like C++ or Python. Android apps are written in JavaSo, You Want To Develop Android Apps? Here's How To LearnSo, You Want To Develop Android Apps? Here's How To LearnAfter so many years, one would think that the mobile market is now saturated with every app imaginable to man - but that's not the case. There are plenty of niches that still need to..Read More, as a practical example.
  • When you install Java on your Mac, you’re installing the Java Runtime Environment, which is relatively secure and a place to run Java-based applications on their own, though it’s not used often. The problem is the included Java Browser plug-in, which enables Java content to run inside any browser on your system.

Recently, Google announced that Chrome will no longer support JavaThe Web Just Became More Secure: Google Drops Support for JavaThe Web Just Became More Secure: Google Drops Support for JavaWhen Java was first released in 1995, it was revolutionary. But now, it's safe to say that Java has lost its shine, and Google is about to drop support for it in Chrome.Read More, meaning that anything online that needs Java will fail to run. This will greatly increase security across the Web, but why?

What’s Wrong With Java?

As Matt explained, Chrome is cutting support for Java because it’s terrifyingly insecure. Security company Kaspersky found that Java caused half of all security attacks affecting computers in 2012; and even people who were using a Windows antivirus weren’t protected.

So what’s the issue here? Essentially, the Java plug-in doesn’t do any sort of check to ensure the content it’s about to run is safe, and with its universal installation base, it’s a perfect target for attack.

Stupidly, Java also doesn’t update itself. Chrome, Firefox, Flash Player, and Adobe Reader all update themselvesWhy Do Apps Nag Me to Update & Should I Listen? [Windows]Why Do Apps Nag Me to Update & Should I Listen? [Windows]Software update notifications seem like a constant companion on every computer. Every app wants to update regularly, and they nag us with notifications until we give in and update. These notifications can be inconvenient, especially..Read More so you don’t have to worry about doing it; why Java can’t implement this critical functionality is anyone’s guess. This leads to a large number of Web users using an outdated version of the plug-in that malicious folks have already picked apart. Most people aren’t going to update softwareHow to Install Mac Apps in Terminal Using HomebrewHow to Install Mac Apps in Terminal Using HomebrewDid you know you can install Mac software in the Terminal? Here's how to use Homebrew to install Mac apps easily.Read More if they don’t see a prompt for it, and many probably don’t even realize that Java is installed on their system.

Of course, we can’t forget the atrocious Ask Toolbar that’s been bundled with Java for years. Every time you install or update Java, you have to remember to uncheck the “sponsored offer” box or else you end up with an ugly Chrome-hijacking toolbar3 Essential Steps To Get Rid Of Chrome Hijackers In Minutes3 Essential Steps To Get Rid Of Chrome Hijackers In MinutesHave you ever opened your browser of choice and been greeted with a bizarre-looking start page or an unsightly toolbar glued to the top of the page? Restore your browser to tip-top shape.Read More glued to your browser. The toolbar can be removed4 Annoying Browser Toolbars and How to Get Rid of Them4 Annoying Browser Toolbars and How to Get Rid of ThemBrowser toolbars just don't seem to go away. Let's look at some common nuisances and detail how to remove them.Read More and even suppressed in the first place, thankfully, but it’s ridiculous that Oracle imposes this on users, contributing to the issue of people failing to update Java.

Seeing the Ask toolbar on my parents PC. It's ok. I know it is tough times for @larryellison and he needs that extra cash, hope it helps!

— Chet Faliszek (@chetfaliszek) September 8, 2015

How to Disable Java

Knowing all this, it’s a good idea to just purge Java from your Mac. Don’t have it installed already? That’s wonderful; certainly don’t start now. For those of you with Java, now’s a great time to completely remove it. If you’re unsure about whether you need it, it’s extremely likely that you don’t.

To check for its presence, open System Preferences and if there’s an entry for Java, it’s installed.

Removal is thankfully a breeze. You’ll need to open a Terminal window4 Cool Things You Can Do With The Mac Terminal4 Cool Things You Can Do With The Mac TerminalThe Terminal is the Mac OS X analogue of the Windows command prompt, or CMD. It's a tool, as you probably already know, that allows you to control your computer using text commands, as opposed..Read More by pressing Command + Space to open Spotlight, then simply search for Terminal to open the prompt. Run the following line (you’ll need to type an administrator password):

Then run:

Java is now extinct from your system; can you feel the safety rushing over you?

If you’re sure you need to leave Java installed for some reason, be sure to take precautionsThe Top 6 Things To Consider When You Install Java SoftwareThe Top 6 Things To Consider When You Install Java SoftwareOracle’s Java runtime software is required to run Java applets on websites and desktop software written in the Java programming language. When installing Java, there are a few things you should consider, especially regarding security..Read More. Here are a few ways you can minimize Java’s risk to your system if you’re keeping it around.

The safest option is to disable Java in all browsersIs Java Unsafe & Should You Disable It?Is Java Unsafe & Should You Disable It?Oracle’s Java plug-in has become less and less common on the Web, but it’s become more and more common in the news. Whether Java is allowing over 600,000 Macs to be infected or Oracle is..Read More. To do this globally, open up the Java Control Panel by going to System Preferences > Java and selecting the Security tab. Uncheck the Enable Java content in the browser box to shut it off everywhere. However, if you need Java for a particular website, this isn’t going to do much good. Instead, you should keep multiple browsers around3 Unmissable Reasons Opera Is the Right Browser for Your Mac3 Unmissable Reasons Opera Is the Right Browser for Your MacChrome and Firefox rule on Windows, but on OS X, Opera is the browser to beat. Eternal favorites Chrome and Firefox can give you flexibility, but not without some heavy compromises.Read More and allow Java in only one of them.

Newer versions of Safari allow Java on a per-site basis; head to Safari > Preferences > Security and choose Website Settings… next to Internet plug-ins. Select Java from the left panel and you can see a list of sites that you’ve given the green light. At the bottom, changing the setting to Block will ensure Java only runs on sites you explicitly allow.

Java automatically checks for updates, but it’s a good idea to ensure you haven’t missed any by occasionally going to the Java Control Panel again and paying a visit to the Update tab, where you’ll be notified of new versions.

Finally, make sure you don’t get hammered with junkware when updating by going to Java Control Panel > Advanced and scrolling all the way down to Suppress sponsor offers… Checking this box puts Java in its place and stops you accidentally installing adware you don’t need.

The Hole in Your Mac’s Security

These security problems aren’t just theory. In the past, Java has been responsible for Mac threats, most notably the Flashback Trojan that took advantage of Java in OS X and affected some 600,000 users. It wasn’t short-lived, either: we reported on Flashback in October 2011New Trojan For Mac Disables XProtect Auto Update [News]New Trojan For Mac Disables XProtect Auto Update [News]A Trojan recently made the rounds for Mac that appeared to be an update for Flash, but was actually a piece of malicious software called Flashback.A. Apple has since updated XProtect to block this dangerous..Read More, February 2012Flashback Mac Trojan Is Back, With A Vengeance [News]Flashback Mac Trojan Is Back, With A Vengeance [News]Read More, and then again in April 2012. Flashback wouldn’t quit, and those without Java installed were safeguarded against the infection.

trying to download bootlegged music to my mac, ended up downloading a virus how ironic

— Val? (@ooohval_) September 13, 2015

Apple computers are generally rock-solid when it comes to security (aside from a few slip-ups like the fake MACDefender antivirus programMalware Disguised As Antivirus Targets Mac Users [News]Malware Disguised As Antivirus Targets Mac Users [News]A bogus version of the MacDefender antivirus application has recently fooled many Apple Mac OSX users into downloading and installing the malware on their computers. The fake antivirus, called MAC Defender, specifically targets Mac users..Read More), so it makes sense that one of the biggest infections on the platform originated from a third-party plug-in. Zero-day vulnerabilitiesWhat Is a Zero Day Vulnerability? [MakeUseOf Explains]What Is a Zero Day Vulnerability? [MakeUseOf Explains]Read More aren’t something to mess around with, and no operating system is immune. Your Mac is secure; keep it that way by obliterating Java’s residence on your machine.

Take a minute to make your Mac even more secure by spotting the signs of a virus3 Signs Your Mac Is Infected With a Virus (And How to Check)3 Signs Your Mac Is Infected With a Virus (And How to Check)If your Mac is acting weird, it could be infected with a virus. How can you check for a virus on your Mac? We'll show you.Read More and putting a stop to annoying pop-upsPop Ups on Your Mac? How to Stop Them Once and For AllPop Ups on Your Mac? How to Stop Them Once and For AllThey break your focus, get in the way and sometimes baffle you. Why won't these pop ups go away?Read More.

Will you be removing Java on your Mac? If you still need Java, what’s making you keep it on your system? Let us know what you think about the plug-in by leaving a comment!

Explore more about: Computer Security, Java.

  1. This article is good, but has some inaccuracies and bias.
    The most obvious claims are that most people don't need Java, that Java does not perform any checks on the software it runs, and the very obvious contradiction of 'Stupidly, Java also doesn’t update itself' followed later by 'Java automatically checks for updates.'

    Java was the first mainstream programming environment to implement the sandbox model of application execution, preventing applications from performing any action outside of the sandbox (aka. virtual machine). When Java applications are written and run properly you do not need to disable this sandboxing. The Australian government clearly violated best practices in having an unsigned application that needs the ability to write to disk, thus requiring the running of Java in an 'unsafe mode.' The new OS model of only running 'signed' applications was actually brought to the mainstream by Java in the 1990's, with jar signing and sandboxing. Besides these obvious misrepresentations of Java, many applications utilize Java, without the user even being aware. It is the exclusion of Java from the OS that has led to each of these applications installing its own version of Java within the application. A perfect example of this is Minecraft, which was written in Java, and ported to .Net after its acquisition by Microsoft. Most parents have this installed and don't even know that it contains the Java Runtime.

    To be fair and unbiased, ALL applications have vulnerabilities and Macs are only safer than Windows and Linux/BSD because the user base is relatively low when compared to these other platforms. The following applications and platforms all have had at least as many security issues as Java, in most case far more, as Java performs extensive bytecode validation before running an application, looking for invalid sequences or known attack vectors, and can easily run applications within a sandbox.

    Adobe's Acrobat Reader, Flash, and Shockwave,
    Microsoft's .Net, Word, Outlook, and the rest of the office suite,
    Open Office, Libre Office, Internet Explorer, Google Chrome, the Safari browser, and any and all means of file/information sharing (torrents, file shares,SSH, web servers, FTP servers, MySQL, all database for that matter, and the list goes on and on) are all vulnerable to exploitation, Zero day or otherwise. This includes all versions of OS X, Windows, and Linux. All software is vulnerable, period. Safe browsing and computer usage should always be executed at all times, not just singling out one of many platforms/applications. Google Chrome's support of Java was terminated when Google stopped supporting the NSAPI, in favor for their browser plugin API. It was not specifically targeted at Java, but the media hyped it as targeted at Java.

    2 very clear examples of vulnerabilities that impacted almost all browsers and OS's were the JPEG and PNG exploits of years past. These vulnerabilities allowed malicious code to bypass the browser and image viewing application using malformed images that trick the computer into executing the malicious code contained within the image. These vulnerabilities were primarily because of the open source/reference implementations written in C/C++ that were vulnerable.

    My point is that just simply uninstalling Java or targeting Java will not secure your system. No one should be using Java Applets or Active X anymore, but the Java Runtime is more secure than most Objective C and C/C++ applications, due in large part to its open public source code review process and security being one of Java's primary design goals. Java is has proven over time to be more secure that Microsoft .Net and Javascript. Javascript, when running in an unsafe mode (allowing the 'eval' operation) is far less secure than any browser plugin.
    Java's largest failing actually being that the automatic updates of the Java runtime has been hampered or disabled by some OS upgrades, which is Apple's fault, not Oracle's or Java's.

    If you want to secure your system, you must disable the Java browser plugin, Flash, Shockwave, and most importantly Javascript, on Windows you must also disable Active X.

  2. Sorry for this late comment; I've just read this great article from Ben. I just have to say this, and it really only affects Australians.

    As a business owner with what's called an Australian Business Number (ABN), I am required to submit a Business Activity Statement (BAS) each quarter. To do that, I have to logon to the Business Portal, but there is a critical step that must be done - authentication using AUSkey, another form of digital ID.
    BUT, guess what? Before any of that happens, Java has to be installed!

    And just to make Java run properly I have to select 'run in unsafe mode' in Safari Preferences.

    So, the ATO requires me to install a vulnerable system on my mac before I can proceed with my civic duty.
    Crazy?

  3. I never really what a terrible piece of software I had on my Mac.

    I just tried to update it as recommended, and it told me it was downloading the update, then that it was extracting the update, then the little window closed and I was back where I started!

    Sorry Java, you are the weakest link - goodbye!

  4. These commands will remove just the browser plugin and the preferences panel, it will leave the Java runtime in your system.

  5. Another great how-to article. But why fill it with other lies that take away from it's awesomeness? Just write your great how-to instructions, and leave it at that.

    '..most Mac users don’t have to worry about running an antivirus or enabling a firewall on OS X.' I have removed viruses multiple times from people that bought into this sentiment. And it cost them hundreds of dollars for each instance. Keep up the good advice (secure everything you hold dear all the time) and stop it with the bad (you don't even need anti-virus because you bought brand 'x').

  6. What about Flash Player is that safe? or does it fall in the same category as java

  7. Why oh why do people continue to promote the fallacy that Mac's are 'rock solid when it comes to security'? Do you read anything other than your own BS?

    http://www.techweekeurope.co.uk/workspace/macs-immunity-to-malware-exposed-as-fallacy-30566
    https://securityintelligence.com/news/new-mac-security-threats-the-perfect-storm/
    http://theartofthehack.com/20-of-the-most-misguided-beliefs-about-infosec/
    http://betanews.com/2015/08/03/macs-are-vulnerable-to-thunderstrike-2-firmware-malware-that-survives-formatting/

    I am not a Mac basher. I am a Security professional and this delusional approach to Mac security must stop.

    Your Mac is NOT secure unless you do something to make it so.

    • True. I've seen it happen in the real world, and it isn't pretty. But it's easier to believe the lie.

  8. I need the JRE and JDK on my mac for my Eclipse IDE to write Java projects.

I've installed JDK 7u7 downloaded from oracle's website. But after installation, the terminal is still showing java version 6

any idea why java 7 is not showing up?

Ans:OK, the problem has been resolved. Here is the answer:I found that my Terminal has a .bash_profile and the java home variable is set to 1.6

What Is Java Used For On My Mac

So this is the line causing the problem every time I opened a new terminal window.Simply remove this line will solve the problem. You still need to follow what @aleroot said, but if that doesn't work for you, check the .bash_profile (or .bashrc) setting file to see if you've previously exported any java version.

Yang
YangYang

26 Answers

Because you need to enter in Java Preferences pane and flag only the JVM 7 in this way :

To easily and quickly open the Java Preferences pane in Mac OS X you can simply call spotlight with +SPACE and type System Preferences it will show up in the last row of the window.

Community
alerootaleroot

Oracle's installer puts java inside the /Library/Internet Plug-Ins/JavaAppletPlugin.plugin. And it doesn't overwrite /usr/bin/java. So, if you issue a

in the terminal, it'll return /usr/bin/java. (which in turn points to /System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/java, which is Apple's 1.6 version).

So, if you want to use the new java version, replace the /usr/bin/java symlink so that it points to /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java instead:

ÁkosÁkos

Install the JDK 7 and this problem will solve itself.

Be sure to get the Java Development Kit (JDK) which includes compilers and stuff like that, rather than just the Java Runtime Environment (JRE) .

BrainO2BrainO2

vi ~/.bash_profile

Mac os x emulator windows 10. How about Roman web designer Alessio Atzeni’s spiritual followup, which emulates Mac OS X Lion’s boot, login and desktop screens using only CSS3 properties, and no image files at all. Yeah, that was pretty impressive. By • 12:40 pm, January 24, 2012 • Remember that we posted about a while back that was made up of nothing but CSS 3 + Javascript, with absolutely no image files used for rendering at all? But you know what’s even more killer?

add

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

This tells your /usr/bin/java link target to use the latest Java 7 Package installed in

/Library/Java/JavaVirtualMachines/

So for JDK 1.7.0_17JAVA_HOME would be:

/Library/Java/JavaVirtualMachines/jdk1.7.0_17.jdk/Contents/Home

Note: There were a lot of change in this area recently to move Mac OS X from Appels own System integrated Java packages to Oracle based Java Packages. The above solution is working fine as of Mac OS X 10.8.2

Uwe GüntherUwe Günther

In my case, the issue was that Oracle was installing it to a different location than I was used to.

Download from Oracle: http://java.com/en/download/mac_download.jsp?locale=en

  1. Verify that it's installed properly by looking in System Prefs:

    • Command-Space to open Spotlight, type 'System Preferences', hit enter.
    • Click Java icon in bottom row. After the Java Control Panel opens, click 'Java' tab, 'View..', and verify that your install worked. You can see a 'Path' there also, which you can sub into the commands below in case they are different than mine.
  2. Verify that the version is as you expect (sub in your path as needed):

    /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -version

  3. Create link from /usr/bin/java to your new install

    sudo ln -fs /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java /usr/bin/java

  4. Sanity check your version:

    java -version

dale.hamilldale.hamill

I had run into a similar issue with terminal not updating the java version to match the version installed on the mac.

There was no issue with the JAVA_HOME environmental variable being set

I have come up with a temporary and somewhat painful but working solution.

In you .bash_profile add the line:

(This is the path on my machine but may be different on yours, make sure to get yours. The paths should match up to /Library/Java/JavaVirtualMachines/)

the run source ~/.bash_profile

As I mentioned this is a temporary band-aid solution because the java home path is being hard-coded. There is really no way to set the path to get the latest as that is what Apple is supposedly doing for terminal already and the issue is that Apple's java_home environment variable is not getting updated.

DerekDerek

Since El Capitan, it is difficult to delete the /usr/bin/java symlink, because of the introduction of the new 'rootless' policy.

Therefore, I simply added the path to the latest java version (in my case this is /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin) to the PATH in my .bashrc file:

To reload your .bashrc file for the current session, run source ~/.bashrc in the shell. You only have to do this for sessions that had been started before changing the .bashrc file.

Now the latest version is used, when you use java in the shell.

TabeaKischkaTabeaKischka

For me the easiest and cleanest way to go is to install Java using homebrew like described here:

Community
Bernhardt SchererBernhardt Scherer

The basic issue: /usr/bin/java is pointing to one provided by OSX itself initially (/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java)We need to point this to the one downloaded by the JDK installer. The below steps are for OSX 10.10.4 Yosemite.

  • Open System Preferences -> select Java. The Java window opens.
  • Click on Java tab at the top. Click on 'View' button.
  • The Java Runtime Environment Settings tab opens as below:
  • Double click on the Path item and copy the path (cmd+c). This is the latest one installed by the JDK installer/updater. In my case, the path was /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java
  • Open terminal. In this step, we are going to point (symbolic link, ln -s command) the system java binary to the latest one, which we discovered in the previous step. Run the below command:

sudo ln -s /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java /usr/bin/java

Thats it. To verify, you can just runjava -versionon the terminal. It should output the latest version that you installed/updated to.

Aswin KumarAswin Kumar

You can execute following command in your terminal :

And this replaces the java old with new one.

Amulya KashyapAmulya Kashyap

I did

and that fixed my Java 8 issue.

before:

after:

Climbs_lika_SpyderClimbs_lika_Spyder

http://www.java.com/en/download/faq/java_mac.xml is a nice place to understand, while Apple is stopping support to Java, why Java Preferences doesn't exist anymore and rely on System_Preferences => Java => Java if Java 7 from Oracle is installed.

revherrevher

May I suggest you to have a look at the tool Jenv

This will allow you to switch at any time between your installed JVMs.

Simply as:

then later for test purpose:

And you have much more commands available.

TitiMobyTitiMoby

Hard-coding the JAVA_HOME path might not be the best idea. The /usr/libexec/java_home utility sill works for me on Mac OSX Lion 10.7.5 and JDK 1.7.0_13. According to its man page, it is meant to be used with Apple's old Java Preferences pane, but it appears to be working with the replacement provided by Oracle (Java Control Panel). For example running /usr/libexec/java_home -V lists all installed JDKs (both 1.6.* and 1.7.*) on my machine.

So, as discussed in other threads (e.g. What should I set JAVA_HOME to on OSX), I would still recommend adding the following line to your .bash_profile:

Community
zagyizagyi

This is nuts! How does Oracle provide an installer that doesn't install anything!?

Anyways for me it was:

where 1.8.0_31 is your installed java version..

Kevin ParkerKevin Parker
MickMick

In case if you have several Java versions on your machine and you want to choose it dynamically at runtime, i.e, in my case, I have two versions:

You can change them by modifying the /etc/profile content. Just add (or modify) the following two lines at the end of the file:

In my case, it should be like the following if I want to use:

Java 7:

Java 8:

After saving the file, please runsource /etc/profile and it should work. Here are results when I use the first and second option accordingly:

Java 7:

Java 8:

The process is similar if your java folder is located in different locations.

nxhoafnxhoaf

I think you can try to install jdk not jre. By installing jdk, the java in /usr/bin/java will be replaced, and all library will work fine.

ParaDevilParaDevil

You can run this command to find the version of Java that's under /Library/Internet Plugins/:

Hefewe1zenHefewe1zen

It is happening because your .bash_profile is not reflecting changes.To reflect it, just use the following command

Raghav SharmaRaghav Sharma

Since i have not faced this issue , I am taking a hunch --

Can you please try this :

Where does the soft link 'java_home' point to :

Output : (Stunted) lrwxr-xr-x java_home -> /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java_home

**ls -lrt /System/Library/Frameworks/JavaVM.framework/Versions My MAC Produces the following :

Based on this , we might get a hint to proceed further ?

user1428716user1428716

i resolved this issue by re installing Yosemite and then cross check java version on terminal (java -version) and (javac -version) .It work perfectly now.It is not changing to java 7 as version 6 still present on (command + n) libray>java>javavirtualmachine>your javac current version.you need to address to java home .

AJAYAJAY

I resolved this issue withsudo rm /usr/bin/java

And I downloaded and installed the last Java SE Runtime Environment:http://www.oracle.com/technetwork/java/javase/downloads/index.html

sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/jre/bin/java /usr/bin/java did not work for me because I got Operation not permitted. El Capitan now protects certain system directories in 'rootless' mode (a.k.a. System Integrity Protection). It is applicable to macOS Sierra, and probably new macOS versions for the foreseeable future.

Charles HamelCharles Hamel

Installing through distributed JDK DMG from the Oracle site auto-updates everything for me. I have seen (in El Capitan) updating through System Preferences > Java do updates but that do not reflect to command line. Installing through DMG does the job.

Santanu KararSantanu Karar

Check JDK versions installed:

Now in your ~/.bashrc export JAVA_HOME specifying the version:

Source the bashrc file and the Java version will be updated:

Miguel MotaMiguel Mota

If you have Homebrew installed, you can install java-switcher to change Java default version more quickly

Then you can use just one command to switch your default Java version.

or

Andy TranAndy Tran

Not the answer you're looking for? Browse other questions tagged javamacosjava-7 or ask your own question.