Skip to content

Lab 0 Setup: Setting Up Your Computer

We encourage you to complete as much of this setup as you can on your own before coming to lab 1. If you get stuck, come to office hours or lab to get help.

A. Installing a Text Editor (optional)

If you don’t already have a favorite text editor, we recommend installing one.

The three most popular GUI text editors these days seem to be:

  1. Sublime Text (free but nags you until you pay): https://www.sublimetext.com/
  2. Atom (free): https://atom.io/
  3. Visual Studio Code (free): https://code.visualstudio.com/

See this text editor review for a more thorough look at these and other text editors.

The choice isn’t very important, as we will only be using a text editor a few times throughout the course. Most of the time we’ll be using something else called an IDE.

You do not need to pick one of the three options above. You’re welcome to use a different text editor entirely (built-in text editors, vim, emacs, etc).

B. Configure Your Computer

Depending on your operating system, there are a few things we need to do to set your computer up for 61B.

The precise steps to take depend on your operating system.

Move on to the next section only once you’ve completed the instructions above for your operating system. Advanced users on Windows may also use the new Bash for Windows feature, but we will not be providing official directions. Note that if you use Bash for Windows, you’ll need to install Java twice (once inside Bash for Windows, and once inside Windows itself, following the directions above).

I choose macOS

b Setup: Mac OS

b. A Setup: Mac OS

  1. Install Homebrew, a very easy to use package manager. To install, go to your Terminal and enter the following:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Note: During the process, you may be prompted to enter a password. When you enter your password, nothing will display on the terminal, but the computer is actually recording your password. This is a security measure. Just type your password and hit enter.

You may be prompted to hit enter again to start the installation after entering your password.

Screenshot 2024-03-08 at 00.36.37

  1. Then, check to make sure brew is working properly on your system by typing:

    brew doctor
    

    You may encounter warnings like this, but you should be fine. Proceed to the next step.

Screenshot 2024-03-08 at 00.37.46

  1. If you encounter a warning asking you to download Command Line Tools, you will need to do this. Please follow the StackOverflow post here.

  2. Install the Java JDK and git. You can do this by typing:

 brew install --cask java
 brew install git

If you’re getting an error for the Java install, try simply:

 brew install java
  1. Verify your git installation by typing:
 git --version

You have successfully installed git if this command returns a valid version number and does not fail.

Similarly, you can verify your Java installation by typing:

 java -version
 javac -version

Both of these commands should succeed and show version 15. If both installations are good, woohoo! Skip the rest of this guide and return to the lab.

Screenshot 2024-03-08 at 00.39.05

b.b Java Install Issues

If you are still having Java install issues with Homebrew after having retried the steps and/or conferring with your TA, it might be time for a manual install. To install Java manually, follow the steps below. If at any point, you believe one of the steps you have done did not work, please get in touch with your TA before proceeding.

  1. Download jdk-15.0.1_osx-x64_bin.dmg from this link and run the installer with the default options

  2. Verify that the download succeeded by typing:

 ls /Library/Java/JavaVirtualMachines

Your output should include JDK 15 (jdk-15.0.1.jdk)

  1. The Java installation should have included a script that outputs the file location of the most recent JDK installed. Run the following command:
 /usr/libexec/java_home

The output you get should look similar to the following, which is the output on my personal computer. In particular, you should see JDK 15 in the output:

 /Library/Java/JavaVirtualMachines/jdk-15.0.1.jdk/Contents/Home
  1. Now, all that remains to do is tell the system where our install folder is. First, run echo $0 to determine if you are running zsh or bash. The next command you have to run will be slightly different depending on whether you are running zsh or bash.

If you are running zsh, type the following command:

 echo 'export JAVA_HOME=$(/usr/libexec/java_home)' >> ~/.zprofile

If you are running bash, type the following command:

 echo 'export JAVA_HOME=$(/usr/libexec/java_home)' >> ~/.bash_profile
  1. This step is important. Completely close out of your terminal window, by typing Cmd + Q. If you have worked with this type of stuff before, you may be tempted to source your zprofile or bash_profile. Do NOT be tempted; simply close out of your terminal with Cmd + Q.

  2. Restart your terminal, and verify that your environment variables have been setup correctly by running:

 echo $JAVA_HOME

The output of this command should be non-empty and include the path to your JDK 15 installation

  1. Java should properly be installed! As mentioned above, you can test this with the commands:
 java -version
 javac -version

b.c Git Install Issues

If you had installation issues with Git using Homebrew, try the instructions “Installing on macOS” at this link. Contact your TA if you are still having issues.

C. Learn to Use the Terminal (Optional)

If you already know how to open and use a terminal, skip this section.

The terminal is an application that allows you to run all sorts of programs, as well as manipulate files in your own computer. It is a powerful but also dangerous tool, so please be careful with using some of these commands. On Unix-like operating systems, the Terminal application will provide you with everything that you need. On macOS, for example, you can use Spotlight to search for the Terminal application.

Here are some important ones that you may find useful in this course:

  • plaintext cd
    : change your working directory
    
    cd hw

This command will change your directory to hw.

  • plaintext pwd
    : present working directory
    
    pwd

This command will tell you the full absolute path for the current directory you are in if you are not sure where you are.

  • plaintext .
    : means your current directory
    
    cd .

This command will change your directory to the current directory (aka. do nothing).

  • plaintext ..
    : means one parent directory above your current directory
    
    cd ..

This command will change your directory to its parent. If you are in /workspace/day1/, the command will place you in /workspace/.

  • plaintext ls
    : list files/folders in directory
    
    ls
    This command will list all the files and folders in your current directory.
    
    ls -l

This command will list all the files and folders in your current directory with timestamps and file permissions. This can help you double-check if your file updated correctly or change the read-write- execute permissions for your files.

  • plaintext mkdir
    : make a directory
    
    mkdir dirname

This command will make a directory within the current directory called dirname.

  • plaintext rm
    : remove a file
    
    rm file1
    This command will remove file1 from the current directory. It will not work if `file1` does not exist.
    
    rm -r dir1

This command will remove the dir1 directory recursively. In other words, it will delete all the files and directories in dir1 in addition to dir1 itself. Be careful with this command!

  • plaintext cp
    : copy a file
    
    cp lab1/original lab2/duplicate

This command will copy the original file in the lab1 directory and and create a duplicate file in the lab2 directory.

  • plaintext mv
    : move or rename a file
    
    mv lab1/original lab2/original
    This command moves `original` from `lab1` to `lab2`. Unlike `cp`, mv does not leave original in the `lab1` directory.
    
    mv lab1/original lab1/newname

This command does not move the file but rather renames it from original to newname.

There are some other useful tricks when navigating on a command line:

  • Your shell can complete file names and directory names for you with tab completion. When you have an incomplete name (for something that already exists), try pressing the tab key for autocomplete or a list of possible names.
  • If you want to retype the same instruction used recently, press the up key on your keyboard until you see the correct instruction. This saves typing time if you are doing repetitive instructions.

I skip

D. Test Run for your Setup from Step B

Let’s ensure that everything is working.

  1. First open up your terminal. Check that git is a recognized command by typing the following command:
 git --version

The version number for git should be printed. If you see “git: command not found”, or similar, try opening a new terminal window, restarting your computer, or installing Git again.

Screenshot 2024-03-08 at 00.42.15

  1. Second, let’s check that javac and java are working. javac and java allow Command Line Compilation, or in other words, the ability to run Java programs directly from the command line. In practice, most developers run Java programs through an IDE like IntelliJ, so we won’t be using command line compilation for much this semester other than testing your setup. Start by running the following commands at your terminal.
 mkdir ~/temp
 cd ~/temp
  1. Then, open your operating system’s file explorer in this directory. You can do this from the command line:

    • Mac: open .

    • Windows: explorer .

    • Ubuntu: gnome-open .

    • Linux Mint: xdg-open . or mate .

      Screenshot 2024-03-08 at 00.43.48

      Screenshot 2024-03-08 at 00.44.03

  2. In this newly opened directory, create a file HelloWorld.java with these contents:

     public class HelloWorld {
         public static void main(String[] args) {
             System.out.println("Hello world!");
         }
     }
    

    Screenshot 2024-03-08 at 00.46.31

    Screenshot 2024-03-08 at 00.46.01

  3. In your terminal, enter ls (list the files/folders in this directory). You should see HelloWorld.java listed.

  4. Run javac HelloWorld.java. If this produces any output, then something may be wrong with your setup. Try opening a new terminal window or restarting your computer. If that still doesn’t work, see the Troubleshooting section under the directions for your operating system.

  5. Type ls, you should see both HelloWorld.java and a freshly created HelloWorld.class (the javac command created this file).

  6. Run java HelloWorld. It should print out “Hello world!” for you. If it didn’t, something is wrong with your setup!

  7. You’re done! You can also delete the “temp” folder and its contents as you please.

The screenshot below shows what we’re hoping for when we do steps 4-7. If you see something similar to this, your java setup is complete.hello_world

Screenshot 2024-03-08 at 00.47.20

E. Install IntelliJ

  1. Download the Community Edition of IntelliJ from the JetBrains website.
  2. After selecting the appropriate version for your OS, click download and wait a few minutes for the file to finish downloading.
  3. Run the installer. If you have an older version of IntelliJ, you should uninstall it at this time and replace it with this newer version. You can use all of the default installation options, with one exception, if you are on Windows, make sure you check the box “Add launchers dir to the PATH”. If you accidentally missed it, the easiest fix is to uninstall intelliJ, and running the installer again, making sure you check that box the second time around. The image below only applies to Windows.

Path

F. Installing the IntelliJ CS 61B Plugins

Begin the setup process by starting up IntelliJ. Then follow the steps below.

Make sure you’re running IntelliJ Version 2020.3.1 or later before continuing. Older versions may also work but we haven’t tried them ourselves.

  1. In the Welcome window, click the “Plugins” button in the menu on the left.Configure Plugin
  2. On the window that appears, click “Marketplace” and enter “CS 61B” in the search bar at the top. The CS 61B plugin entry should appear. If you click the autocomplete suggestion, a slightly different window from what is shown below may appear – this is okay.
  3. Click the green Install button, and wait for the plugin to download and install.Search CS 61B
  4. Now, search for “Java Visualizer”, and click the green Install button to install the plugin.Search Java Visualizer
  5. If it appears, click the green Restart IDE button to finalize the installation. If you don’t see a Restart IDE button, just continue.

For more information on using the plugins, read the plugin guide. You don’t have to read this right now.

Screenshot 2024-03-08 at 00.48.50

G. Celebrate

Phew! You’re finally done setting everything up. You can now proceed to lab 1.