Skip to content
Subscribe to RSS Find me on GitHub Follow me on Twitter

JavaScript auf Mac installieren: A Step-by-Step Guide

JavaScript auf Mac installieren: A Step-by-Step Guide

If you own a Mac and want to learn programming, build websites, or automate tasks, installing JavaScript is your gateway to a vast ecosystem of tools and possibilities. While JavaScript originally ran only inside web browsers, today you can run it directly on your Mac using Node.js—a powerful runtime that lets you execute JavaScript code from your Terminal, build servers, create command-line tools, and manage project dependencies.

This guide is designed for absolute beginners. We’ll walk through every step slowly, explain what each command does in plain language, and help you avoid the pitfalls that trip up most newcomers. By the end, you’ll have a flexible, professional-grade JavaScript setup that can grow with you for years.

Why You Need More Than Just a Browser

You might wonder: “My browser already runs JavaScript—why install anything?” That’s a fair question. Browser JavaScript is limited to web pages and can’t access your file system or run scripts independently. When you install Node.js on your Mac, you get a standalone JavaScript engine that can:

The installation process involves three main pieces: Homebrew (a package manager that simplifies installing software), nvm (a version manager that lets you switch between Node.js versions), and Node.js itself (the JavaScript runtime). This combination gives you maximum flexibility and makes updates painless.

What You’ll Need Before Starting

Don’t worry if Terminal looks intimidating—we’ll only use a few simple commands, and you’ll understand exactly what each one does before you type it.

Step-by-Step Installation

Follow these steps in order. Each builds on the previous one, so skipping ahead will cause errors.

Step 1: Install Homebrew

Homebrew is a free, open-source package manager for Mac. Think of it as an app store for command-line tools and developer software. Instead of downloading installers manually and clicking through setup wizards, Homebrew lets you install complex software with a single command.

Open Terminal and paste this command:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

What this command does: It downloads and runs the official Homebrew installation script. The curl part fetches the script from GitHub, and the /bin/bash -c part executes it safely on your system. You’ll see a lot of text scroll by as Homebrew installs itself and creates its directory structure. The process takes 2-5 minutes depending on your internet speed.

When prompted, press Return to continue and enter your Mac password. The password field won’t show characters as you type—that’s normal security behavior.

How to verify Homebrew installed correctly: After the script finishes, type:

brew --version

You should see something like Homebrew 4.2.0 or higher. If you see “command not found,” close Terminal completely, reopen it, and try again.

Step 2: Install nvm (Node Version Manager)

Now that Homebrew is ready, we’ll use it to install nvm. The Node Version Manager is a small program that lets you install multiple versions of Node.js and switch between them easily. This is crucial because different projects may require different Node versions, and nvm keeps everything organized.

In Terminal, run:

brew install nvm

What this command does: Homebrew downloads nvm and all its dependencies, then places it in the correct system directory. This takes about 30 seconds.

After Homebrew finishes, you need to tell your Mac where to find nvm each time you open Terminal. Create a directory for nvm and add configuration to your shell profile:

mkdir -p ~/.nvm
echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.zshrc
echo '[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh"' >> ~/.zshrc
echo '[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm"' >> ~/.zshrc

What these commands do: The first line creates a hidden folder called .nvm in your home directory where Node versions will be stored. The next three lines append configuration commands to your .zshrc file (the configuration file for your Terminal shell). These commands load nvm automatically whenever you open a new Terminal window.

Important: Close Terminal completely (Cmd+Q) and reopen it. This loads the new configuration. If you skip this step, your Mac won’t recognize nvm commands.

Step 3: Install Node.js (LTS Version)

With nvm active, you can now install Node.js. We’ll install the LTS (Long-Term Support) version, which is the most stable and widely supported release—perfect for beginners and production work alike.

In Terminal, run:

nvm install --lts

What this command does: nvm contacts the Node.js servers, downloads the latest LTS version, compiles it for your Mac, and installs it in the .nvm directory. This takes 1-3 minutes.

After installation, tell nvm to use this version:

nvm use --lts

What this command does: It activates the LTS version you just installed, making it available in your current Terminal session and setting it as the default for future sessions.

Step 4: Verify Your Installation

Finally, confirm everything works by checking the versions of Node.js and npm:

node -v
npm -v

What these commands do: node -v prints the version of Node.js currently active (e.g., v20.10.0). npm -v prints the version of the Node Package Manager that comes bundled with Node.js (e.g., 10.2.3). If both show version numbers, congratulations—you have a working JavaScript environment!

Understanding What You Just Installed

Let’s take a moment to understand the three tools now on your system:

Homebrew is your Mac’s new software manager. You can use it to install Git, Python, databases, and hundreds of other developer tools with simple brew install commands. It keeps everything updated and organized.

nvm is your Node.js version switcher. If you ever need an older Node version for a specific project, just type nvm install 18 and nvm use 18. nvm keeps each version isolated, preventing conflicts. You can list all installed versions with nvm ls and see what’s available with nvm ls-remote.

Node.js is the JavaScript engine. It reads your .js files and executes them. It also includes npm, which is the world’s largest software registry, containing over a million free libraries you can add to your projects.

Your First JavaScript Code Examples

Let’s run two simple examples to see your new tools in action.

Example 1: Hello World Script

Create a file named hello.js on your Desktop. You can use TextEdit (in plain text mode) or any code editor. Paste this code:

// This is a comment - JavaScript ignores it
// The line below prints text to your Terminal
console.log("Hello from Node.js on my Mac!");

What this code does: The console.log() function is JavaScript’s way of printing output. When Node.js runs this file, it executes the function and displays the message in Terminal.

Save the file, then in Terminal, navigate to your Desktop and run:

cd ~/Desktop
node hello.js

You should see Hello from Node.js on my Mac! printed below your command. You just ran your first JavaScript program!

Example 2: Using npm to Install a Package

npm lets you add powerful libraries to your projects. Let’s create a simple project that uses the lodash library (a popular utility toolkit).

First, create a project folder and navigate into it:

mkdir my-project
cd my-project

Initialize a new Node.js project:

npm init -y

What this does: npm init creates a package.json file that tracks your project’s dependencies. The -y flag accepts all default settings, saving you from answering a dozen questions.

Now install lodash:

npm install lodash

What this does: npm downloads the lodash library from its registry and saves it in a node_modules folder. It also updates package.json to record lodash as a dependency.

Create a file called app.js in the my-project folder:

// Load the lodash library
const _ = require('lodash');

// Use lodash's shuffle function to randomize an array
const colors = ['red', 'green', 'blue', 'yellow'];
const shuffled = _.shuffle(colors);

console.log('Original colors:', colors);
console.log('Shuffled colors:', shuffled);

What this code does: The require() function loads the lodash library. We then use lodash’s shuffle method to randomize the order of colors in our array. Each time you run this script, you’ll get a different random order.

Run it with:

node app.js

You’ll see output showing both the original and shuffled arrays. You’ve just leveraged the power of npm’s ecosystem!

Common Mistakes and How to Avoid Them

Even with clear instructions, beginners often hit these snags:

1. Installing Node.js from the Official Website Downloading the .pkg installer from nodejs.org seems logical, but it bypasses nvm. You’ll be stuck with one version and may face permission headaches. Always use nvm for installation.

2. Forgetting to Close Terminal After Configuring nvm The .zshrc file only loads when Terminal starts. If you don’t close and reopen Terminal after Step 2, you’ll get “nvm: command not found” errors. Remember: Cmd+Q, not just closing the window.

3. Using sudo with nvm or npm Never type sudo nvm install or sudo npm install. This forces commands to run as the root user, creating files with wrong permissions that cause endless problems. nvm is designed to work without sudo. If you get permission errors, it means something else is misconfigured—using sudo only makes it worse.

4. Typos in the Configuration Commands Those long echo commands in Step 2 must be copied exactly. A missing quote or bracket will break your shell configuration. If Terminal starts acting strangely after you edit .zshrc, you can reset it by opening the file in TextEdit: open ~/.zshrc and carefully removing the broken lines.

5. Not Creating the .nvm Directory If you skip mkdir -p ~/.nvm, nvm may fail to install Node versions. The directory must exist before nvm tries to use it.

Troubleshooting: When Things Go Wrong

Here are solutions to the most common problems:

Problem: “brew: command not found” after installing Homebrew

Problem: “nvm: command not found” after Step 2

Problem: “Permission denied” when running nvm or npm

Problem: Node version is old after installing

Problem: npm install hangs or fails

Problem: Terminal shows weird characters or beeps

Summary

You now have a professional JavaScript development environment on your Mac. You installed Homebrew to manage software, nvm to handle Node.js versions, and Node.js itself to run JavaScript code. You verified everything works and even ran your first scripts using both core Node.js and an external npm package.

This setup gives you the flexibility to learn, experiment, and build real projects. As you grow, you can install additional Node versions with nvm install, explore thousands of npm packages, and even install other developer tools like Git or Python using Homebrew.

Remember the key principles: never use sudo with nvm or npm, always close Terminal after configuration changes, and keep your tools updated with brew update and nvm install --lts periodically. If you encounter errors, re-read the command carefully, check for typos, and consult the troubleshooting section.

Your Mac is now a JavaScript powerhouse. Happy coding!