{"id":18840643,"url":"https://github.com/lana-20/java-setup","last_synced_at":"2026-01-29T17:30:19.545Z","repository":{"id":180287770,"uuid":"615597936","full_name":"lana-20/java-setup","owner":"lana-20","description":"Java Setup","archived":false,"fork":false,"pushed_at":"2023-11-05T12:27:07.000Z","size":54,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-30T09:46:52.401Z","etag":null,"topics":["appium-java","appium-selenium-setup","environment-variables","java","selenium-java","setup","setup-macos","setup-windows"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lana-20.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-03-18T05:24:39.000Z","updated_at":"2023-10-26T03:13:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"cd709631-42bd-48ab-940a-4ce5949324ce","html_url":"https://github.com/lana-20/java-setup","commit_stats":null,"previous_names":["lana-20/java-setup"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lana-20%2Fjava-setup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lana-20%2Fjava-setup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lana-20%2Fjava-setup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lana-20%2Fjava-setup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lana-20","download_url":"https://codeload.github.com/lana-20/java-setup/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239777940,"owners_count":19695403,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["appium-java","appium-selenium-setup","environment-variables","java","selenium-java","setup","setup-macos","setup-windows"],"created_at":"2024-11-08T02:48:26.386Z","updated_at":"2026-01-29T17:30:19.502Z","avatar_url":"https://github.com/lana-20.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"NOTE: This repo has been published as a [post](https://medium.com/@begunova/java-setup-macos-and-windows-5cbdf15b1670) on Medium.\n\n# Java Setup\n\nIn the context of Appium and Selenium automation, we think about how we would get a working setup on our local machine. The first thing we want to make sure is present is something called Java. Java is a programming language and set of tools that are used by both Appium and Selenium.\nFirst of all, you can check to see if you already have Java on your machine. It often comes on computers by default nowadays, or you may have already installed it for another purpose. To check if you have it installed, open up either a terminal on macOS, or a command prompt on Windows, and run the appropriate 'echo' command here:\n\n- Mac: \u003ccode\u003eecho $JAVA_HOME\u003c/code\u003e\n- Win: \u003ccode\u003eecho %JAVA_HOME%\u003c/code\u003e\n\nFor Mac, I would get output that looks something like:\n\n    /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home\n\nOr:\n\n    /usr/local/Cellar/openjdk@11/11.0.15/libexec/openjdk.jdk/Contents/Home\n\nWhereas for Windows, it would look like:\n\n    C:\\Program Files\\java\\jdk1.8.0_221\n\nThat's nice, but maybe nothing got printed out. And what am I actually doing anyway? What is the point of these commands? On each platform, these commands are designed to print out the value of something called environment variables.\n\nLet's take a brief digression to understand environment variables since they're important, especially, for getting Appium set up. Environment variables are just like variables in any programming language, like *python*. They're little names that can hold values, and can change over time. Environment variables are designed to be variables that exist in the terminal, or across my whole system. Environment variables are made available to any program that I run from the terminal session where the variable is defined. And I probably already have lots of environment variables set by default, without realizing it.\n\nFor example, if I'm on a Mac, open up a terminal and type \u003ccode\u003eecho $HOME\u003c/code\u003e. I should get back something that looks like \u003ccode\u003e/Users/lanabegunova\u003c/code\u003e, as mine is.\n\nOr, if you’re on Windows, open up a command prompt and type \u003ccode\u003eecho %HOMEPATH%\u003c/code\u003e. You should get back something that looks like \u003ccode\u003e\\Users\\lanabegunova\u003c/code\u003e, based on my computer's username.\n\nOn either platform, what's going on is that the path to your home folder has been saved as an environment variable. Here are a couple more key points about environment variables:\n1. Environment variables are only valid in the terminal session where they are defined. If you define an environment variable in one terminal window, and then open up another one, the variable will not exist in the other one. There is a way to make variables persist across sessions, which I'll discuss momentarily.\n2. To check the value of the environment variable, I can use the \u003ccode\u003eecho\u003c/code\u003e command. On mac, I put a dollar sign in front of the variable name. On Windows, I put percent signs around the variable name.\n3. To set environment variables from the terminal, we can use the \u003ccode\u003eexport\u003c/code\u003e command on mac, or the \u003ccode\u003eset\u003c/code\u003e command on Windows. For example, I can run export \u003ccode\u003eHELLO=world\u003c/code\u003e on macOS, or \u003ccode\u003eset HELLO=world\u003c/code\u003e on Windows. In both cases, I don't use the dollar sign or percent signs when assigning values to the variables.\n\nLet's see this in action now. I'll run the export command first:\n\n    export HELLO=world\n\nWhich defines the variable \u003ccode\u003eHELLO\u003c/code\u003e. And now I can try to echo it out, by ensuring that I use the dollar sign when I reference the variable:\n\n    echo $HELLO\n\nAnd sure enough I get \u003ccode\u003eworld\u003c/code\u003e printed out. But now let's try something. I'll open up a new terminal window, and run the same \u003ccode\u003eecho\u003c/code\u003e command. What happens? I get nothing printed out, which means the variable is not defined. That's because our \u003ccode\u003eexport\u003c/code\u003e command only set the variable in that particular terminal session. Variables don't span multiple sessions.\n\nBut It's often really important to have environment variables set for one reason or another, and it's a pain to set them by hand every time I open a terminal window. So let's talk about how to make it seem like I can persist these variables across sessions. On Mac, it looks like adding the export command I just saw to something called a shell startup script. By the way, when I say \"shell\", that's just another way of talking about the program I'm using when I open up the terminal. \n\nWhenever I open up a shell, the shell process tries to read certain files, called startup scripts, to see if I have put any commands in those files for it to run automatically. I can include environment variable exports in these shell startup scripts. The tricky part is figuring out which file I need to create or edit in order to have it work.\n\nOn macOS, the file we can create or edit will depend on our operating system. If you have a version older than Catalina, then the file will be called \u003ccode\u003e.bashrc\u003c/code\u003e. That \u003ccode\u003e.\u003c/code\u003e in front makes it a hidden or invisible file, and it needs to be located in my home directory. It's called \u003ccode\u003ebashrc\u003c/code\u003e because it's a startup script for the Bash shell, which is the default in older versions of macOS. To figure out if this file exists, I can run the following command: \u003ccode\u003els ~/.bashrc\u003c/code\u003e. On Mac and Linux, the \u003ccode\u003e~\u003c/code\u003e character is a shortcut to my home directory, so this is basically asking the system to list the file called \u003ccode\u003e.bashrc\u003c/code\u003e in the home directory. \n\nIf I'm on Catalina or higher, the default shell for macOS is something called Zsh or Z shell, and its startup script file is \u003ccode\u003e~/.zshrc\u003c/code\u003e instead. So basically, look for a \u003ccode\u003e~/.bashrc\u003c/code\u003e or a \u003ccode\u003e~/.zshrc\u003c/code\u003e file as appropriate for your version of macOS. (In all the instructions that follow, I'll just mention ~/.bashrc, so substitute ~/.zshrc for my case if necessary.)\n\n        % ls ~/.zshrc\n        /Users/lanabegunova/.zshrc\n\nIf you get a filename listed as the output of that \u003ccode\u003els\u003c/code\u003e command, great! Otherwise, if the \u003ccode\u003e.bashrc\u003c/code\u003e file does not exist, no problem - you'll just need to create one. So let's go ahead and open up a text editor and I can load that file, or create it if it doesn't already exist in my home directory. So I'll get the open dialog up. There's a problem here, however, which is that the dialog doesn't show hidden files by default. To get them to show up, we need to use a special Mac keyboard shortcut: \u003ccode\u003eCMD+SHIFT+period\u003c/code\u003e. Now I can see the hidden files, and I'll open up \u003ccode\u003e.bashrc\u003c/code\u003e. If there's other text in there already, just ignore it for now, it's fine. What I want to do is to create a new line at the very bottom:\n\n        export HELLO=world\n\nNow let's save the file, and close any open terminal windows. Open a new terminal, and try the \u003ccode\u003eecho $HELLO\u003c/code\u003e command again. Now, it should print out \"world\", and it should do that in the future as well. So that's how we set environment variables automatically for future terminal sessions on macOS.\n\nOn Windows, it's a bit different, and it's best to use the system UI to make this change. First, I'll open up a command prompt however, and try to echo the variable to show that it's not yet set:\n\n        echo %HELLO%\n\nRemember on Windows that when we refer to environment variables, we put percent signs around them. Now let's set up this custom environment variable. First, you want to open up the Start menu and start searching for 'Advanced system settings'.\n\nNow you can open up that control panel item, and it will go straight to the 'advanced' tab of the system properties control panel. Towards the bottom, you'll see a button that says \"Environment Variables...\". That's what we want, so click it. In the window that pops up, you'll see two sections, one section for user variables and one section for system variables. If you only care about setting these things up for my single user, it's fine to focus on the user variables, otherwise, focus on the system variables. Let's create a new user variable by clicking \"New...\" underneath that section.\n\nThis opens up a dialog where I can enter a name and a value. Enter \"HELLO\" as the name and \"world\" as the value, then click OK. Now, save and exit out of all the dialogs, and open up a new command prompt. In this prompt, I can again type \u003ccode\u003eecho %HELLO%\u003c/code\u003e and I should see 'world' printed back to me! So that's how I set environment variables persistently on Windows.\n\nBack to making sure we have Java set up. Remember, the commands we ran to see if it was accessible via the right environment variable are \u003ccode\u003eecho $JAVA_HOME\u003c/code\u003e on Mac or \u003ccode\u003eecho %JAVA_HOME%\u003c/code\u003e on Windows. If you got a value printed out there, examine it. Does it have the string \"jdk\" somewhere in it? And is the version number 1.8 or higher? If so, you're in luck! It appears Java is already set up correctly.\n\n\u003cimg width=\"500\" src=\"https://user-images.githubusercontent.com/70295997/226087741-eb99600a-c274-416e-98ac-e481422d6b1a.png\"\u003e\n\n        % echo $JAVA_HOME\n        /usr/local/Cellar/openjdk@11/11.0.15/libexec/openjdk.jdk/Contents/Home\n\nWhat if we got something printed out, but it doesn't say \"jdk\"? Maybe it says \"jre\". In that case we'll need to download and install a new version of Java. This is because Appium needs to have something called the JDK, or the Java Development Kit, because this version of Java has more tools bundled with it than the JRE, or the Java Runtime Engine alone. Likewise, if we got nothing printed out at all, then we'll need to install Java.\n\nThe standard way to install Java is to head to [java.com/download](java.com/download) and follow the instructions for your platform. However, this takes you through a convoluted series of pages and clicks. So instead, head directly to https://www.oracle.com/java/technologies/javase-downloads.html#javasejdk, which is a long link but will save you some time. You will need to download and run an installer for the JDK from that page. Ensure it's the JDK and not the JRE. When you run the downloaded installer, make a note of where you install Java, because we're going to need that information. So go ahead and install Java now.\n\nNow that we've installed Java, we need to set the special JAVA_HOME environment variable. And when I say set the environment variable, I mean going through the steps appropriate for my system that I demonstrated earlier. So on Windows, we do this again by opening up the environment variables area of the advanced system settings, creating a new variable called JAVA_HOME, and as the value setting the path where we installed Java. For example, \u003ccode\u003eC:\\Program Files\\java\\jdk1.8.0_222\u003c/code\u003e.\n\nOn macOS, it's a bit different. I know how to set environment variables in my \u003ccode\u003e.bashrc\u003c/code\u003e file now, but how do I know where Java was installed? To figure that out it's easiest to use a little helper program that comes with Java. So I can open up a terminal and run the command \u003ccode\u003e/usr/libexec/java_home\u003c/code\u003e. See what it prints out? For me it's:\n\n\u003cimg width=\"500\" src=\"https://user-images.githubusercontent.com/70295997/226088586-159ce970-3cbe-4ef0-b0d2-d616f881e8f9.png\"\u003e\n\n        /usr/local/Cellar/openjdk@11/11.0.15/libexec/openjdk.jdk/Contents/Home\n\nFor you it might look different. \n\n        /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home\n\nRegardless, that is the path we should use as the content of the JAVA_HOME variable. Notice that on macOS, it also looks a bit different than on Windows, because it includes a *Contents* and a *Home* directory. But we'll take this string, open up our \u003ccode\u003e.bashrc\u003c/code\u003e file, and create the appropriate \u003ccode\u003eexport\u003c/code\u003e statement at the end:\n\n        export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home\n\nWith any export command, there's something we need to be aware of. If there are any spaces in it, we need to put the value in quotes. In fact, it's safe to always put things in quotes so it's not a bad idea to do that. Let's update our variable to use quotes for safety:\n\n        export JAVA_HOME=\"/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home\n\nNow I have JAVA_HOME set on macOS as well.\n\nNext, we're going to work with yet another environment variable. This one is called PATH. The purpose of the PATH environment variable is to define a list of directories. These directories are the ones our shell will look in when we want to execute a command. Why do we need to do this? Just because I have a program somewhere on my computer doesn't mean I can just type its name to run it from a shell.\n\nWhy would we *want* to run a program by its name rather than by a full path? Because some programs are so useful we end up using them in lots of places, and it would be tedious to have to type out the full path all the time.\n\nThe Java JDK comes with a lot of little programs, some of which Appium uses in order to do its work. It makes life easier to have all these little programs on my PATH. So the first step is figuring out where these little programs live. First, let's check out what's inside my Java directory, by running a command that allows us to list the contents of a directory. On macOS, this is the \u003ccode\u003els\u003c/code\u003e command, which we can use in conjunction with our newly set environment variable:\n\n\u003cimg width=\"500\" src=\"https://user-images.githubusercontent.com/70295997/226089135-5a2152c4-2e21-43de-8d68-3a7c703b23a8.png\"\u003e\n\n        ls $JAVA_HOME\n        bin\tconf\tdemo\tinclude\tjmods\tlegal\tlib\tman\trelease\n\nNow there's everything that's inside of JAVA_HOME.\n\nOr on Windows, we use the \u003ccode\u003edir\u003c/code\u003e command to do the same thing:\n\n        dir \"%JAVA_HOME%\"\n\nIn each case, we'll get out a directory listing. Notice a directory inside of my JAVA_HOME folder called \u003ccode\u003ebin\u003c/code\u003e. Bin is short for 'binaries' and it's where all these little programs are. So what I want to do is make sure this \u003ccode\u003ebin\u003c/code\u003e directory is somehow a part of my PATH environment variable.\n\nTo update the PATH variable on macOS, we open up our \u003ccode\u003e.bashrc\u003c/code\u003e file that we've been editing, and check to see if any PATH variable is being exported in it. If so, we can just modify that line. If not, we can create a new line that starts with:\n\n        export PATH=$PATH\n\nThe first thing I do is set PATH to itself. Why do I set PATH to itself? Well, PATH may have some values in it already set from some previous shell startup script, and I don't want to clobber those. So I first make sure that I'm keeping any existing values. Then, I add the directory I want to the PATH, by changing the line so that it looks like this:\n\n        export PATH=$PATH:$JAVA_HOME/bin\n\nNow I am using two environment variables to define PATH -- any previous PATH value, and my new JAVA_HOME variable. Since I'm using JAVA_HOME, I need to write this PATH export line after I define the JAVA_HOME variable. And all I'm doing is telling the PATH that I want whatever is inside the bin dir inside JAVA_HOME to be on the path. I can add as many directories as I want to the PATH, by separating them with colons. This is how I build up my list of directories in my path.\n\nOn Windows, we head to the Environment variable editor as before. In either your user or system variables, you should see an existing variable called \u003ccode\u003ePath\u003c/code\u003e. Click to edit it. The editor for the Path variable is special - it shows us a list of paths, and we can add to this list by clicking \"New\". So click new and add \u003ccode\u003e%JAVA_HOME%\\bin\u003c/code\u003e, then save it to the list. Notice that again we are using another environment variable to help define the Java binary directory we want to use in our path. This means that if you change the value of JAVA_HOME down the line, say because you downloaded a new version of Java, you don't also need to update your Path.\n\nSome older versions of Windows have the Path variable as one long string, in which case the value works just the same as it does on Mac, just separate each directory with semicolons instead of colons (and make sure to use the Windows format for variables and paths of course).\n\nWe have now set our Java home environment variable and our path variable in such a way that we should have access to the Java binary programs from our shell without needing to know where they are anymore. So open up a new terminal or command prompt, and check if this is the case by trying to run the \u003ccode\u003ejava\u003c/code\u003e command. If it works, you should get a bunch of help output from \u003ccode\u003ejava\u003c/code\u003e, as shown below. And note that whether you are on Mac or Windows, you can run the same Java command.\n\n        lanabegunova@Lanas-iMac ~ % java\n        Usage: java [options] \u003cmainclass\u003e [args...]\n                   (to execute a class)\n           or  java [options] -jar \u003cjarfile\u003e [args...]\n                   (to execute a jar file)\n           or  java [options] -m \u003cmodule\u003e[/\u003cmainclass\u003e] [args...]\n               java [options] --module \u003cmodule\u003e[/\u003cmainclass\u003e] [args...]\n                   (to execute the main class in a module)\n           or  java [options] \u003csmycefile\u003e [args]\n                   (to execute a single smyce-file program)\n\n\n         Arguments following the main class, smyce file, -jar \u003cjarfile\u003e,\n         -m or --module \u003cmodule\u003e/\u003cmainclass\u003e are passed as the arguments to\n         main class.\n\n\n         where options include:\n\n\n            -cp \u003cclass search path of directories and zip/jar files\u003e\n            -classpath \u003cclass search path of directories and zip/jar files\u003e\n            --class-path \u003cclass search path of directories and zip/jar files\u003e\n                          A : separated list of directories, JAR archives,\n                          and ZIP archives to search for class files.\n            -p \u003cmodule path\u003e\n            ...\n\nIf it doesn't work, if you didn't get output similar to this, then go back through these steps or check the java installation documentation or usage for your shell to make sure that you've set up your environment correctly. Remember we can always echo environment variables to make sure they have the content we expect. For example, I can echo out the two variables I added:\n\n\u003cimg width=\"600\" src=\"https://user-images.githubusercontent.com/70295997/226089617-7e72967f-44a3-4fcb-a867-7ec31bbf2ab9.png\"\u003e\n\n        % echo $JAVA_HOME\n        /usr/local/Cellar/openjdk@11/11.0.15/libexec/openjdk.jdk/Contents/Home\n\n        % echo $PATH\n        /usr/local/opt/openjdk@11/bin:/Library/Frameworks/Python.framework/Versions/3.11/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Java/JavaVirtualMachines/openjdk-11.jdk/Contents/Home/bin:/usr/local/opt:/Users/lanabegunova/Library/Android/sdk/emulator:/Users/lanabegunova/Library/Android/sdk/platform-tools\n\n(And on Windows, make sure to use the % signs of course). So that's it for setting up Java and our Java environment.\n\n----\n_#TODO1: Update all samples to Java 11 for consistency._\n_#TODO2: Recalibrate refs to bashrc/zshrc for consistency._\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flana-20%2Fjava-setup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flana-20%2Fjava-setup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flana-20%2Fjava-setup/lists"}