---
slug: "macで、ターミナルからJavaScriptスクリプトファイルを実行する"
title: "Run a JavaScript Script File from the Terminal on Mac"
description: "Run a JavaScript file directly from the macOS Terminal — install Node.js and add a shebang line to make the script executable, step by step."
url: "https://www.ytyng.com/en/blog/macで、ターミナルからJavaScriptスクリプトファイルを実行する"
publish_date: "2014-06-13T03:00:08Z"
created: "2014-06-13T03:00:08Z"
updated: "2026-05-11T13:03:47.048Z"
categories: ["mac"]
keywords: ""
featured_image_url: "https://media.ytyng.com/resize/20230812/26e4f65f09c64e259e7064e7616e9550.png.webp?width=768"
has_video: false
has_music: false
video_urls: []
music_urls: []
lang: "en"
---

# Run a JavaScript Script File from the Terminal on Mac

```bash
#!/usr/bin/env jsc
print("Hello, World!");
```

To execute such a JS file from the terminal, it's convenient to use the JSC that comes pre-installed on Mac.

<h3>1. Add JSC Interpreter to Your Path</h3>

The JavaScript interpreter on a Mac is located here:

```bash
/System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc
```

Since it's not in the PATH by default, create a symbolic link in a directory that is in the PATH.

For example, you might use /usr/local/bin.

```bash
cd /usr/local/bin
ln -s /System/Library/Frameworks/JavaScriptCore.framework/Versions/A/Resources/jsc ./
```

In the terminal, run:

```bash
jsc --help
```

If the help information is displayed, it's set up correctly.

<h3>1.1. Using the Interactive Interface</h3>

Run:

```bash
jsc
```

This will start an interactive interface. The prompt and behavior are very similar to Python's interactive interface.

You can even write functions.

<img src="http://ytyng.com/picture/mac/jsc/jsc-001.png" style="width:240px;"/><br/>

<h3>2. Write Your JS File</h3>

```bash
#!/usr/bin/env jsc
print("Hello, World!");
```

Save this as `hello.js`.

<h3>3. Make the File Executable</h3>

```bash
chmod +x hello.js
```

<h3>4. Execute the File</h3>

```bash
./hello.js
```

<br/>
<img src="http://ytyng.com/picture/mac/jsc/jsc-002.png" style="width:158px;"/><br/>

Reference:

<a href="http://d.hatena.ne.jp/modified/20110506/1304647677">Running JS in Mac's Terminal - modified's diary</a>
