6  Troubleshooting

In this final chapter, let’s touch quickly on navigating common issues you might run into using the terminal.

6.1 Common pitfalls and errors

Here’s a quick rundown of the most common problems and errors you’ll run into using the command line. Even experienced developers run into these issues, so learning what they mean will go a long way when troubleshooting.

  • Command not found? You might have a typo or the program isn’t installed.
  • No such file or directory? You might be trying to access a file/path that doesn’t exist. Check that the file exists and that you spelled it correctly. You could also not be in the directory you think you are — try running pwd or ls to check your location, then use the cd to navigate where you should be if needed.
  • Permission denied?
    You tried to do something you don’t have permission to do. Check your file/repo permissions.
  • Syntax error
    You typed a command in a way the shell doesn’t understand. Check that your syntax is correct and error-free.
  • Stuck in a weird app inside Terminal?
    Try pressing Ctrl + C or Ctrl + D to exit. (You may need to checkout “How to get out of Vim” below)

For more common issues and how to fix them, see the Common errors table in the Glossary at the end of this guide.

6.2 How to Get Out of Vim

Every new command line user shares one panic-inducing experience at one point or another: accidentally opening Vim and not knowing how to get out of it.

In this section, we’ll briefly walk you through what Vim is and how to exit it so you don’t panic when this (inevitably) happens to you.

What is Vim?

Vim is a text editor built into most Unix systems, including macOS and Linux. It’s used by developers to edit code and configuration files, but it works very differently from regular text editors.

If you accidentally open something in Vim (for example, by running git commit without a message), it might look like you’re stuck. But don’t worry — here’s how to exit safely.

How to Exit Vim

If you don’t want to save any changes (most common):

  1. Press Esc - to make sure you’re not in input mode.
  2. Type :q! - to “quit and ignore changes”.
  3. Hit Enter / return - to exit.

If You do want to save changes (less common):

  1. Press Esc
  2. Type :wq (to “write and quit”).
  3. Press Enter / return

6.3 Change Mac shell to bash

Mac Catalina changes the default shell program from Bash to zsh. While zsh is a great shell, we are using Bash in this class for consistency.

  1. Open a Terminal

  2. Copy or Type and run this command:

    chsh -s /bin/bash
  3. You will be asked to enter your computer password. YOU WON’T SEE KEYSTROKES AS YOU TYPE in your password. Just type it in anyway and hit Return. If you flub the password, you’ll have to enter the above command again.

  4. If you don’t get an error, close your terminal and reopen it and it should say “bash” at the top.

Alternative method:

If for some reason that doesn’t work, there is this way, too:

  1. Choose Apple menu  > System Settings, then click Users & Groups.

  2. Click the lock, then enter your account name and password.

  3. Control-click your user name in the list of users on the left, then choose Advanced Options.

  4. Choose a shell from the ”Login shell” menu, then click OK to save the changes.

    Default to bash
  5. Click OK and close the System Preferences window.

  6. Close any Terminal windows you have open and restart them.