HOW TO SWITCH JAVA VERSION and SET JAVA_HOME PATH ON MAC OS M1 M2

Поділитися
Вставка
  • Опубліковано 1 чер 2024
  • STEP 1 : Open Terminal. Check java version java -version
    STEP 2 : Check java compiler version javac -version
    STEP 3 : Run command /usr/libexec/java_home -V This will show the available versions
    STEP 4 : Goto folder - /Library/Java/JavaVirtualMachines This should have folders of all Java/JDK available on the system
    STEP 5 : Goto the folder of JAVA you want and get the path of its home folder (which has bin folder)
    STEP 6 : On terminal run the following commands
    echo $JAVA_HOME
    export JAVA_HOME=JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home
    echo $JAVA_HOME
    To set the path permanently
    echo $SHELL
    Note: if you are using older mac os, for the command echo $SHELL you may get result like .bash_profile
    Then your default profile is bash and the changes you will make will be in file .bash_profile and not .zshrc
    So you can replace in the below commands .zshrc with .bash_profile
    pwd
    open .zshrc
    nano .zshrc | vi .zshrc
    open .zshrc
    Add the following:
    export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home
    export PATH="/Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home/bin:$PATH"
    Save and close
    source .zshrc
    STEP 7 : Open a new terminal and check
    java -version
    javac -version
    echo $JAVA_HOME
    ------------------------------------------
    how to change java version on mac m1 m2
    how to switch between java versions on mac
    how to set JAVA_HOME path on mac m1 m2
    how to set java home path in file permanently
    ------

КОМЕНТАРІ • 46

  • @geralddeloach2421
    @geralddeloach2421 8 днів тому +1

    Before I found your video I was struggling tremendously trying to figure out my java issue. I am learning Salesforce development and I was stuck at step 1 trying to get my VS Code connected and operable with Salesforce DX due to incompatible java versions. I had version 22 set as my default and could not figure out how to delete it or switch over to 17. I stopped trying for a month. This was so easy and clear to follow. Thank you!

    • @RaghavPal
      @RaghavPal  8 днів тому

      So happy to hear this helped Gerald .. humbled

  • @rosehuang8709
    @rosehuang8709 Місяць тому

    Really appreciate you also explained the vi/nano command as I'm very new to cmd. Super helpful!

    • @RaghavPal
      @RaghavPal  Місяць тому

      Glad it was helpful Rose

  • @user-xn6rj4nw3w
    @user-xn6rj4nw3w 4 місяці тому

    Thansk for great explanation. I have a question
    Should I remove export JAVA_HOME=$(/usr/libexec/java_home) from my zshrc?
    It was already there and java -version was pointing 21 but I needed 17 and I put path for 17 at the end of zshrc file

    • @RaghavPal
      @RaghavPal  4 місяці тому

      Necmettin
      Here's my take on it
      Understanding the Line:
      - Purpose: This line dynamically sets the `JAVA_HOME` environment variable to the path of the default Java version on your system, as determined by the `/usr/libexec/java_home` command.
      Your Situation:
      - Desired Java 17: You need Java 17 for your project.
      - Manual Path Set: You've already set the `JAVA_HOME` path to Java 17 at the end of your zshrc file.
      Recommendations:
      - Remove the Dynamic Line: Since you've manually specified the path to Java 17, keeping the dynamic line might lead to conflicts or unexpected behavior. It's generally recommended to remove it to ensure clarity and consistency in your environment.
      Steps:
      1. Open zshrc: Use a text editor to open your zshrc file. It's typically located in your home directory: `~/.zshrc`.
      2. Comment or Remove:
      - Comment: Add a `#` at the beginning of the line to temporarily disable it without removing it:
      ```bash
      # export JAVA_HOME=$(/usr/libexec/java_home)
      ```
      - Remove: Delete the line entirely to permanently remove it.
      3. Source zshrc: Apply the changes to your current shell session:
      ```bash
      source ~/.zshrc
      ```
      Verification:
      - Check Java Version: Confirm that `java -version` now points to Java 17:
      ```bash
      java -version
      ```
      Additional Considerations:
      - Multiple Java Versions: If you need to switch between Java versions frequently, consider using tools like `jenv` or `sdkman` to manage multiple installations seamlessly.
      - Project-Specific Requirements: If you're working with projects that require specific Java versions, using version managers or setting `JAVA_HOME` within those project environments can help isolate dependencies.
      By following these steps and considering the additional points, you can effectively manage your Java environment and ensure the correct version is used for your projects.

  • @marcelorodrigues000
    @marcelorodrigues000 Місяць тому

    You`ve helped me a lot! Thank you!

    • @RaghavPal
      @RaghavPal  Місяць тому

      Most welcome Marcelo

  • @havvanyc91
    @havvanyc91 Місяць тому

    I can't thank you enough. You have helped me a ton!

  • @guillermoramirez668
    @guillermoramirez668 Місяць тому

    thank you my friend!! very helpful video!!

    • @RaghavPal
      @RaghavPal  Місяць тому

      Glad it was helpful Guillermo

  • @svenstito6897
    @svenstito6897 4 місяці тому +1

    Hi Raghav,
    Thank you for creating all these amazing videos, your content is amazing and is helping me learn test automation. I am learning Python and Selenium using Python by following your playlists. I do have the following two questions for you:
    1 - Will you be making some more videos on Selenium using Python, like advanced frameworks or advanced reporting?
    2 - Is the following certification worth pursuing, PCAT - Certified Associate Tester with Python? If, Yes can you please recommend a good course for it?
    Regards
    Svens

    • @RaghavPal
      @RaghavPal  4 місяці тому +1

      Svens
      1. Yes, I will plan more lectures on these topics
      2. I am not very sure on this

  • @vikrambahure8639
    @vikrambahure8639 2 місяці тому

    THANK YOU SO MUCH
    I AM ABLE TO SUCESSFULL DO THAT BY USING THIS VIDEO

    • @RaghavPal
      @RaghavPal  2 місяці тому

      Great to know this Vikram

  • @adihanrafiga4562
    @adihanrafiga4562 4 місяці тому +1

    Hello, can you make a tutorial for automation with Appium and Python along with installation with or without Android Studio. Thank You

  • @ashishnaidu2487
    @ashishnaidu2487 4 місяці тому

    Hello Raghav, I'm really sorry as I was not sure where to ask this question but as needed so posted here, is there any plan in near future that you start tutorials on 'Selenium automation using C#' please?
    The reason being our company uses C# for automation and it would be great help if you make tutorials on this course please.
    Thanks again a lot once again for providing such a valuable knowledge to us.

    • @RaghavPal
      @RaghavPal  4 місяці тому

      Ashish
      yes, actually i have been planning that for long, but somehow it's getting delayed everytime. I will try to start on it as early as I can

    • @ashishnaidu2487
      @ashishnaidu2487 4 місяці тому

      @@RaghavPal ❤ thanks a lot! for considering my request.

  • @MarioEduradoGonzalezFlores
    @MarioEduradoGonzalezFlores Місяць тому

    Hi Raghav,
    Im having trouuble in step 3. When I run the command /"usr/libexec/java_home -V" my terminal says this "he operation couldn’t be completed. Unable to locate a Java Runtime." What can I do?
    Thks for your content, is really useful!

    • @RaghavPal
      @RaghavPal  Місяць тому

      Mario
      If you're encountering the "Unable to locate a Java Runtime" error on your Mac, there are a few steps you can take to resolve it:
      1. Install Java JDK or JRE:
      - First, ensure that you have Java installed on your system. As of now, you can install Java versions from Java 8 to Java 21 on your Mac². It's recommended to get a stable LTS (Long Term Supported) version of Java.
      2. Using Homebrew:
      - Open your terminal and run the following command to install OpenJDK 11 (you can choose other versions as well):
      ```
      brew install openjdk@11
      ```
      - To make sure the system can find this JDK, create a symbolic link:
      ```
      sudo ln -sfn $(brew --prefix)/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk
      ```
      3. Check Java Security Settings:
      - Go to System Preferences > Java > Security.
      - Make sure that "Enable launching Java Web Start applications from the browser" is enabled, even when launching them without a browser⁴.
      4. Verify Java Installation:
      - Run the following command to check if Java is correctly set up:
      ```
      java -version
      ```
      - You should see information about the installed Java version.
      5. Update Environment Variables:
      - Ensure that your `PATH` environment variable includes the correct path to the Java installation.
      - You can add the following line to your shell profile (e.g., `.zshrc` or `.bashrc`):
      ```
      export PATH="/usr/local/opt/openjdk@11/bin:$PATH"
      ```
      6. Restart Your Terminal:
      - After making changes, close and reopen your terminal to apply the updates.
      Remember to replace `openjdk@11` with the desired Java version if you prefer a different one. Once you've completed these steps, try running your command again. It should locate the Java Runtime successfully.

  • @kal7270
    @kal7270 Місяць тому

    Thank you so much. I went through the steps, set the JAVA HOME path permanently. However, once I open new terminal and check the version, its still returning JAVA 8. I have been sitting trying to solve this issue for 2 days now. Anyone please help!

    • @RaghavPal
      @RaghavPal  Місяць тому

      Goto Terminal
      Add path in .bash_profile (old macs)
      Or .zshrc (new macs)
      Starting with macOS Monterey (released in 2021), Apple switched the default shell from Bash to Zsh for new user accounts
      Check what is our default Shell echo $SHELL
      For e.g. for command echo $SHELL you got response as /bin/zsh
      that means your default shell is zsh (also called Z shell) and you will add env variables in file .zshrc
      (Else your default shell will be bash and you will add all env variables in file .bash_profile. And if that is the case just replace .zshrc with .bash_profile in all below commands)
      Now assuming the default shell is Zsh and we need to add env variables in .zshrc file
      Open Terminal
      Run command open .zshrc
      In case the file does not already exist, create the file touch ~/.zshrc
      This command creates the .zshrc file in your home directory (~ )
      Now to edit .zshrc file we have 2 options
      On terminal, run command open .zshrc
      This should open the file in a text editor where you can edit and save it
      Add the below mentioned env variables and save the file
      If option 1 does not work, On terminal, run command cat .zshrc
      This will show the contents of the file on the terminal itself
      Now use vi editor to edit the file
      Run command vi .zshrc this will open file in vi editor
      Press i on keyboard to go into insert mode
      Now add the env variables as shown below (make sure to update the paths as per your system)
      export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-21.jdk/Contents/Home
      export PATH=$PATH:$JAVA_HOME/bin
      here you can also use $HOME in place of your home directory (e.g. /Users/raghavpal)
      Also notice, to give path of bin folder instead of mentioning the complete path we can refer from env variable
      JAVA_HOME that we have already set by using $JAVA_HOME
      After editing press escape key on the keyboard
      Now write wq! and hit Enter. This will write and quit
      To check the paths are set, open a new terminal and run commands
      cat .zshrc
      echo $JAVA_HOME
      echo $PATH
      Mac OS - To find all versions of JAVA available on the system and set a specific version
      Run command /usr/libexec/java_home -V This will show the available versions
      STEP 4 : Goto folder - /Library/Java/JavaVirtualMachines This should have folders of all Java/JDK available on the system
      STEP 5 : Goto the folder of JAVA you want and get the path of its home folder (which has bin folder)
      Update the path in JAVA_HOME and PATH env variables
      To remove Java
      Remove path for JAVA_HOME from shell file (.zshrc or .bash_profile)
      Check java -version in new terminal
      If you still get response
      Run command
      env
      Check if you see JAVA_HOME
      If yes run
      unset JAVA_HOME
      References:
      How to install Java JDK on Mac OS and set JAVA_HOME variable - ua-cam.com/video/mAIxIhVJ7N0/v-deo.html
      How to Switch Java Version and set JAVA_HOME on Mac OS with Apple M1 M2 chip - ua-cam.com/video/-ecG6B_jNW8/v-deo.html
      ..

  • @exploringgilgitbaltistan2390
    @exploringgilgitbaltistan2390 5 місяців тому

    thanks sir for reply but here no any new video its 4 or 3 year back sir
    i need new one dear sirrrrrr
    kindly help mostly students avoid automation because selenium setup is complex and no any new video on selenium setup

    • @RaghavPal
      @RaghavPal  4 місяці тому

      As soon as possible

  • @Alkhattab1
    @Alkhattab1 2 місяці тому

    Hello, when I Entering Echo $JAVA _HOME Nothing Show in the Terminal.

    • @RaghavPal
      @RaghavPal  2 місяці тому

      If you're trying to display the value of the `JAVA_HOME` environment variable in your terminal, but nothing is showing up, there are a few steps you can take to troubleshoot this. Let's go through them:
      1. Check if JAVA_HOME is Set:
      - First, confirm whether you have set the `JAVA_HOME` environment variable at all.
      - Open your terminal and type the following command:
      ```
      echo $JAVA_HOME
      ```
      - If it returns `%JAVA_HOME%` (or nothing), it means the variable is not set.
      2. Windows Command Prompt (cmd.exe):
      - If you're using Windows Command Prompt, try this:
      ```
      echo %JAVA_HOME%
      ```
      - It should display the correct path to your Java installation (e.g., `C:\Program Files\Java\jdk1.7.0_80`).
      3. Git Bash (within Windows):
      - If you're using Git Bash within Windows, use the following command:
      ```
      echo $JAVA_HOME
      ```
      - Again, it should show the correct path.
      4. Windows PowerShell:
      - In Windows PowerShell, you can use either of these commands:
      ```
      Get-ChildItem Env:JAVA_HOME
      ```
      or
      ```
      echo $env:JAVA_HOME
      ```
      - Both should display the correct Java home directory.
      5. Linux and macOS:
      - On Linux or macOS, simply use:
      ```
      echo $JAVA_HOME
      ```
      - It should show the correct path.
      6. Double-Check the Path:
      - Make sure the path you've set for `JAVA_HOME` is correct. It should point to the root directory of your Java installation.
      Remember that environment variables are case-sensitive, so ensure you're using the correct capitalization. If you're still having issues, double-check your Java installation and verify that the `JAVA_HOME` variable is correctly set.

  • @exploringgilgitbaltistan2390
    @exploringgilgitbaltistan2390 5 місяців тому +1

    Sir I am from Gilgit Baltistan
    Sir I want to start selenium automation using java
    Will you please make a video of its installation with every new version setup and first test case to visit website..
    I need a vedio of selenium setup using java..
    Please help me

    • @RaghavPal
      @RaghavPal  5 місяців тому +1

      Can find these videos here - automationstepbystep.com/

  • @RENU_TALKSS
    @RENU_TALKSS 4 місяці тому

    I learned performance testing with loadrunner tool sir and I've 5y career gap dou to govt jobs preparation.now what's the approach to get the job sir ??

    • @RaghavPal
      @RaghavPal  4 місяці тому +1

      Getting a job in performance testing after a 5-year career gap due to government job preparation requires a strategic approach. Here are some steps you can take:
      1. Highlight relevant skills and experience:
      * Focus on transferable skills: While your experience hasn't been directly in performance testing, highlight relevant skills gained during your govt job preparation, such as analytical thinking, problem-solving, time management, and data analysis. These skills are valuable in performance testing.
      * Quantify your achievements: Did you lead any projects, analyze data to draw conclusions, or implement efficiency measures? Quantify your achievements using metrics to demonstrate your effectiveness.
      * Relevancy of LoadRunner: Though LoadRunner may not be the latest tool, emphasize your proficiency in its core concepts like performance metrics, script development, and load generation. This knowledge can be translated to other tools.
      2. Upskill and bridge the gap:
      * Refresh your LoadRunner knowledge: Take online courses or participate in boot camps to refresh your LoadRunner skills and stay updated with the latest features.
      * Learn new performance testing tools: Research popular tools like JMeter, NeoLoad, k6, and SoapUI. Choose one or two to learn based on industry demand and your career goals. Free online resources and tutorials are available.
      * Contribute to open-source projects: Participating in open-source performance testing projects can showcase your practical skills and passion for the field.
      3. Network and build your brand:
      * Connect with performance testing professionals: Attend industry events, conferences, and workshops. Join online communities and forums to network with professionals and learn about current trends.
      * Build your online presence: Create a LinkedIn profile showcasing your skills and experience. Share relevant articles, blogs, and projects to demonstrate your knowledge and passion.
      * Reach out to recruiters: Contact recruiters specializing in performance testing roles. Express your enthusiasm and willingness to learn, highlighting your transferable skills and desire to bridge the gap.
      4. Emphasize your learning agility and dedication:
      * Be transparent about your career gap: Address your gap upfront and frame it as a period of self-improvement and skill development. Highlight the skills you gained during that time.
      * Showcase your eagerness to learn: Show your willingness to learn new tools and adapt to industry changes. Your passion for performance testing and learning mindset will be appreciated.
      5. Tailor your resume and cover letter:
      * Customize your resume for each job application: Highlight relevant skills and experience mentioned in the job description. Quantify your achievements and use keywords from the job posting.
      * Write a compelling cover letter: Explain your career journey and motivation for pursuing performance testing. Connect your skills and experience with the specific requirements of the job.
      Remember, landing a job after a career gap requires initiative, perseverance, and a willingness to learn. By highlighting your relevant skills, upskilling yourself, and building your network, you can increase your chances of success in performance testing.
      I hope this helps! Good luck with your job search!

    • @RENU_TALKSS
      @RENU_TALKSS 4 місяці тому

      @@RaghavPal ok tq sir

  • @NaveenKumar-gb8ug
    @NaveenKumar-gb8ug 4 місяці тому

    I am an automation tester with knowledge in Selenium (Java), Cucumber, Appium, and API Testing (Postman and RestAssured). How much salary can I expect with 1.5 years of experience in Chennai and Bangalore?"

    • @RaghavPal
      @RaghavPal  4 місяці тому +1

      Naveen
      With your 1.5 years of experience as an automation tester with the skillset you mentioned (Selenium (Java), Cucumber, Appium, and API Testing (Postman and RestAssured)), you can expect a decent salary in both Chennai and Bangalore. Here's a breakdown:
      Salary Range:
      * Chennai: 4.5 Lakhs per annum (₹450,000) to 7 Lakhs per annum (₹700,000)
      * Bangalore: 5 Lakhs per annum (₹500,000) to 8 Lakhs per annum (₹800,000)
      Factors Affecting Salary:
      * Specific skills and experience: The depth of your knowledge in each tech stack and your experience with specific projects can significantly impact your salary. Strong expertise in frameworks like Appium or RestAssured can be particularly advantageous.
      * Company size and type: MNCs and product-based companies generally offer higher salaries compared to startups or service-based companies.
      * Negotiation skills: Don't hesitate to negotiate your salary based on your qualifications and market value.
      Additional Considerations:
      * Bonus and benefits: Some companies offer attractive bonuses, stock options, and comprehensive health insurance, which can add to your overall compensation package.
      * Location within the city: Certain areas in Bangalore might offer slightly higher salaries compared to others.
      Remember: 1.5 years is still early in your career. Focus on continuously improving your skills, gaining experience on diverse projects, and building a strong portfolio. This will put you in a better position to command a higher salary in the future.
      I hope this information helps.. best wishes

    • @NaveenKumar-gb8ug
      @NaveenKumar-gb8ug 4 місяці тому

      @@RaghavPal Thank you so much for this information and your tutorial videos, sir.

  • @myt7791
    @myt7791 2 місяці тому

    .zshenv:1: command not found: Export
    Do you know what is this mean?
    I'm getting with error whenever open the new terminal.
    Example: Last login: Thu Mar 7 17:34:17 on ttys000
    /Users/praveenbhuvaneswaran/.zshenv:1: command not found: Export

    • @RaghavPal
      @RaghavPal  2 місяці тому

      The error message `.zshenv:1: command not found: Export` suggests that there is a typo in your `.zshenv` file. The correct command should be `export` (all lowercase), not `Export`. The shell commands are case-sensitive, and having the wrong case can lead to such command not found errors.
      To fix this, you'll need to edit the `.zshenv` file and correct the command. Here's how you can do it:
      1. Open the terminal.
      2. Type `nano ~/.zshenv` and press Enter to open the file in the nano text editor.
      3. Look for the line that contains `Export` and change it to `export`.
      4. Save the changes by pressing `Ctrl + O`, then press Enter.
      5. Exit nano by pressing `Ctrl + X`.
      After making these changes, the error should no longer appear when you open a new terminal window. If you're not comfortable using nano, you can use any other text editor you're familiar with to make this change. Remember to be cautious when editing configuration files like `.zshenv` to avoid further issues.
      .

    • @myt7791
      @myt7791 2 місяці тому

      Thank you, sir @RaghavPal. The error is gone now. Once again, thank you for your valuable comments. I subscribed to you.👍