Gemma 4をUbuntu24.04 LTSにインストール

Ubuntu 24.04環境にGoogleの大規模言語モデル「Gemma 4(ジェマ フォー)」をローカル環境で動かせるようにしてみます。

ローカルLLMに興味はあっても、「どのようにインストールすればいいのか」「GPUは使えるのか」「モデルはどこに保存されるのか」など、実際に構築してみないと分からないことも多くあります。

そこで、NVIDIA GeForce RTX 4060 Ti(16GB)を搭載したPCに、Ollamaを利用してGemma 4を導入します。

環境

Ubuntu 24.04.5 LTS
NVIDIA GeForce RTX 4060 Ti 16GB
メモリ 128GB

$ cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04.5 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.5 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo
$ uname -r
6.8.0-142-generic
$ nvidia-smi
Thu Sep 24 22:57:55 2026
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 580.178.04             Driver Version: 580.178.04     CUDA Version: 13.0     |
+-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GeForce RTX 4060 Ti     Off |   00000000:2B:00.0  On |                  N/A |
| 70%   56C    P3             24W /  165W |      10MiB /  16380MiB |      0%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI              PID   Type   Process name                        GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|  No running processes found                                                             |
+-----------------------------------------------------------------------------------------+
$ free -h
               total        used        free      shared  buff/cache   available
Mem:           125Gi       2.5Gi       122Gi        10Mi       2.2Gi       123Gi
Swap:           15Gi          0B        15Gi

モデルの保存先ディレクトリーの作成

モデルの保存先を格納するディレクトリーを作成します。

$ LANG=C lsblk -o NAME,SIZE,FSTYPE,LABEL,UUID,MOUNTPOINTS | grep -B 2 '/ai' ・・・ マウントポイントの確認
nvme0n1                   238.5G
`-nvme0n1p1               238.5G LVM2_member                  tfGnf3-Gesx-kcaT-Fk6O-804v-I8vC-1PVPv5
  `-aivg-ailv             238.5G xfs                          4a24b6af-1aa3-483f-8ddf-57fe84ad4724   /ai
$ sudo mkdir -p /ai/ollama/models
$ LANG=C ls -ld /ai/ollama/models
drwxr-xr-x 2 root root 6 Sep 26 00:42 /ai/ollama/models

Ollamaインストールスクリプトのダウンロード

Ollamaの公式からインストールシェルスクリプトをダウンロードします。

$ curl -fsSL https://ollama.com/install.sh -o /work/ollama-install.sh
$ LANG=C ls -l /work/ollama-install.sh
-rw-rw-r-- 1 user01 user01 15902 Sep 26 00:52 /work/ollama-install.sh
curlコマンドのオプション意味
-fHTTPエラーが発生した場合、失敗として扱う
-ssilent。進捗状況などを表示しない
-S-s使用時でもエラーは表示する
-Lリダイレクト先があれば追跡する
-o取得した内容を指定したファイルに保存する

Ollamaインストールスクリプトの実行

$ sudo sh /work/ollama-install.sh
>>> Installing ollama to /usr/local
>>> Downloading ollama-linux-amd64.tar.zst
############################################################## 100.0%
>>> Creating ollama user...
>>> Adding ollama user to render group...
>>> Adding ollama user to video group...
>>> Adding current user to ollama group...
>>> Creating ollama systemd service...
>>> Enabling and starting ollama service...
Created symlink /etc/systemd/system/default.target.wants/ollama.service →
 /etc/systemd/system/ollama.service.
>>> NVIDIA GPU installed.

インストール完了の確認とサービスの状態

インストールが完了するとサービスは自動で起動しています。

$ ollama --version
ollama version is 0.34.4
$ systemctl status ollama | grep -e Loaded -e Active
     Loaded: loaded (/etc/systemd/system/ollama.service; enabled; preset: enabled)
     Active: active (running) since Sat 2026-09-26 09:54:45 JST; 6min ago

Ollamaのモデル保存先を設定

モデルは容量が大きいので保存先を変更しています。

変更前のサービス設定の確認

$ systemctl cat ollama
# /etc/systemd/system/ollama.service
[Unit]
Description=Ollama Service
After=network-online.target

[Service]
ExecStart=/usr/local/bin/ollama serve
User=ollama
Group=ollama
Restart=always
RestartSec=3
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

[Install]
WantedBy=default.target

サービス設定ファイルのドロップイン設定

オリジナルのサービス設定ファイルに変更を加えずに、ドロップイン設定で追加します。

$ sudo SYSTEMD_EDITOR=vim systemctl edit ollama ・・・ ドロップイン設定のためエディタ起動
### Editing /etc/systemd/system/ollama.service.d/override.conf
### Anything between here and the comment below will become the contents of the drop-in file


[Service]
Environment="OLLAMA_MODELS=/ai/ollama/models"
・・・ ここに設定を追加

### Edits below this comment will be discarded


### /etc/systemd/system/ollama.service
# [Unit]
# Description=Ollama Service
# After=network-online.target
#
# [Service]
# ExecStart=/usr/local/bin/ollama serve
# User=ollama
# Group=ollama
# Restart=always
# RestartSec=3
# Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
#
# [Install]
# WantedBy=default.target

ファイルを保存して終了させるとメッセージが出力されます。

Successfully installed edited file '/etc/systemd/system/ollama.service.d/override.conf'.

変更後のサービス設定確認

$ systemctl cat ollama
# /etc/systemd/system/ollama.service
[Unit]
Description=Ollama Service
After=network-online.target

[Service]
ExecStart=/usr/local/bin/ollama serve
User=ollama
Group=ollama
Restart=always
RestartSec=3
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

[Install]
WantedBy=default.target

# /etc/systemd/system/ollama.service.d/override.conf
[Service]
Environment="OLLAMA_MODELS=/ai/ollama/models"

Ollamaのモデル保存先確認

$ sudo systemctl daemon-reload ・・・ systemdの設定を再読み込み
$ sudo systemctl restart ollama ・・・ Ollamaサービスをリスタート
$ systemctl show ollama --property=Environment ・・・ Ollamaの環境変数を確認
Environment=PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin OLLAMA_MODELS=/ai/ollama/models ・・・ Ollamaのモデル保存先
$ LANG=C ls -ld /ai/ollama/models 
drwxr-xr-x 3 root root 19 Sep 26 10:36 /ai/ollama/models
$ sudo chown -R ollama:ollama /ai/ollama/models ・・・ モデル保存先の所有者とグループの変更
$ LANG=C ls -ld /ai/ollama/models
drwxr-xr-x 3 ollama ollama 19 Sep 26 10:36 /ai/ollama/models

Ollamaのモデルを取得

$ ollama list ・・・ インストール済みのモデルを表示(新規なので何もない)
NAME    ID    SIZE    MODIFIED
$ ollama pull gemma4:12b ・・・ Gemma 4 12Bモデルを取得
pulling manifest
pulling 1278394b6936: 100% ??????????????????????????????????????????????? ? 7.4 GB/7.4 GB   10 MB/s      0s
pulling 675ad6e68101: 100% ??????????????????????????????????????????????? ? 175 MB/175 MB   10 MB/s      0s
verifying sha256 digest
writing manifest
success
$ ollama list ・・・ インストール済みのモデルを表示
NAME          ID              SIZE      MODIFIED
gemma4:12b    4eb23ef187e2    7.6 GB    3 hours ago
$ LANG=C ls -l /ai/ollama/models
total 4
drwxr-xr-x 2 ollama ollama 4096 Sep 26 10:52 blobs ・・・ モデル本体のデータ
drwxr-xr-x 3 ollama ollama   32 Sep 26 10:53 manifests ・・・ モデルの管理情報
drwxr-xr-x 2 ollama ollama  174 Sep 26 14:13 metadata ・・・ Ollamaのモデル関連メタデータ

動作確認

$ sudo systemctl status ollama.service | grep Active
     Active: active (running) since Sat 2026-09-26 10:36:04 JST; 2 days ago
$ ollama run gemma4:12b
>>> Send a message (/? for help) ・・・ プロンプトが出てきたら質問ができる

いくつかの質問をしてみます。

>>> こんにちは。簡単に自己紹介してください。 ・・・ 会話的な質問をしてみる
Thinking...
*   User says: "こんにちは。簡単に自己紹介してください。" (Hello. Please introduce yourself briefly.)
    *   Context: The user is asking who I am and what I can do.

    *   I am a large language model trained by Google.
    *   Key capabilities: Answering questions, generating text (creative, informative, etc.), translating, coding assistance, and general
conversation.
    *   Tone: Polite, helpful, and friendly.

    *   *Draft 1 (Internal Monologue):* こんにちは。私はGoogleによってトレーニングされた大規模言語モデルです。質問に答えたり、文章を書いたり
、翻訳をしたりできます。何かお手伝いしましょうか?

    *   *Draft 2 (Adding more flair):* こんにちは!私はGoogleによってトレーニングされたAIです。さまざまな質問にお答えしたり、文章の作成、翻
訳、プログラミングのサポートなど、幅広いことがお手伝いできます。あなたの良きパートナーとして、何でも相談してください。

    *   *Refining for the specific Japanese persona (helpful/polite):*
        *   Greeting: こんにちは!
        *   Identity: Googleによってトレーニングされた大規模言語モデルです。
        *   Functions:
            1.  質問への回答 (Answering questions)
            2.  文章の作成・要約・翻訳 (Writing, summarizing, translating)
            3.  アイデア出しや相談 (Brainstorming, advice)
            4.  プログラミングの補助 (Coding help)
        *   Closing: お手伝いできることがあれば、いつでもお気軽に話しかけてください。

    "こんにちは!私はGoogleによってトレーニングされたAI(大規模言語モデル)です。

    私は以下のようなことをお手伝いできます:
    *   **質問への回答**: 一般知識から専門的な内容まで、幅広くお答えします。
    *   **文章の作成・推敲**: メール、レポート、物語の作成や、文章の添削、要約を行います。
    *   **翻訳**: 複数の言語を互いに翻訳します。
    *   **プログラミングのサポート**: コードの作成やデバッグの相談に乗ります。
    *   **アイデア出し**: 旅行の計画や、プレゼントのアイデアなど、一緒に考えることができます。

    どんなことでも、気軽に話しかけてくださいね。今日はどのようなお手伝いができますか?"

    (Self-correction: Keep it concise as requested "簡単に".)

    *Revised Concise Version:*
    こんにちは!私はGoogleによってトレーニングされた大規模言語モデルです。

    質問への回答、文章の作成や翻訳、プログラミングの相談など、さまざまなことにお手伝いすることができます。

    何か知りたいことや、手伝ってほしいことがあれば、いつでも気軽にお話しください!

    *   Greeting: Yes.
    *   Simple: Yes.
    *   Accurate: Yes.
...done thinking.

こんにちは!私はGoogleによってトレーニングされた大規模言語モデルです。

私は以下のようなことなど、さまざまなお手伝いができるAIです。

*   **質問に答える**(知識に関する質問、日常の疑問など)
*   **文章の作成や推敲**(メール、レポート、物語の作成、要約など)
*   **翻訳**(複数の言語間での翻訳)
*   **プログラミングのサポート**(コードの作成やエラーの解決など)
*   **アイデア出し**(企画の相談や、旅行の計画など)

何か知りたいことや、お手伝いできることがあれば、いつでもお気軽にお話しくださいね!

>>> 1から10までの数字を足すといくつですか? ・・・ 計算の質問をしてみる
Thinking...
*   Input: "1から10までの数字を足すといくつですか?" (What is the sum of numbers from 1 to 10?)
    *   Task: Calculate the sum of integers from 1 to 10.

    *   Sum = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10
    *   Method 1 (Manual addition):
        *   1+2=3
        *   3+3=6
        *   6+4=10
        *   10+5=15
        *   15+6=21
        *   21+7=28
        *   28+8=36
        *   36+9=45
        *   45+10=55
    *   Method 2 (Arithmetic Series formula):
        *   Formula: $n(n+1) / 2$
        *   $n = 10$
        *   $10 \times (10+1) / 2 = 10 \times 11 / 2 = 110 / 2 = 55$.

    *   Result: 55.
    *   Format: Direct answer + optional explanation (optional but helpful).

    *   "1から10までの数字を足すと、**55**になります。" (The sum of numbers from 1 to 10 is 55.)
...done thinking.

1から10までの数字をすべて足すと、**55**になります。

>>> 今日の年月日は? ・・・ 今日の年月日を聞いてみる
Thinking...
*   User asks: "今日の年月日は?" (What is today's date?)
    *   Language: Japanese.
    *   Context: The user wants to know the current date.

    *   Current Date (UTC): 2024-05-23 (Note: As an AI, I need to check the system clock or current date provided by the environment).
    *   *Self-correction/Adjustment:* My internal system time shows today is May 23, 2024.
    *   *Wait, let me double-check the actual current date.* Today is May 23, 2024.

    *   *Constraint:* I am an AI model, and while I know the date, I should provide it clearly in the requested format (Year, Month, Day).
    *   *Format:* Year/Month/Day (e.g., 2024年5月23日).

    *   Direct answer: 今日は2024年5月23日です。

    *   "今日は2024年5月23日です。"

    *(Wait, I need to make sure I have the correct real-time date if the system provides it. Let's check the system time provided by the
environment.)*
    Current Date: May 23, 2024.

    *Response:* 今日は2024年5月23日です。

    (Wait, I should check if there are any specific nuances. Just providing the date is sufficient.)

    "今日は2024年5月23日です。"
...done thinking.

今日は2024年5月23日です。 ・・・ 実際の年月日と違う回答が返ってきた「AI(Gemma)が現在の年月日を知らないため)」

>>> Send a message (/? for help)

「今日の年月日は?」の質問をしたとき、間違った回答をしてくるのは、Gemmaが、Ubuntuのシステム時計から現在の年月日を取得していないためです。そのため、「今日の年月日は?」と質問しても、実際の日付とは異なる回答をします。

今日の年月日を、こちらから教えてあげることで、認識してくれます。ただし、Gemmaを再度、実行しなおすと忘れてしまいます。

>>> 今日は2026年9月28日です。 ・・・ AI(Gemma)に教えてあげます
Thinking...
*   The user previously asked "What is today's date?" and I replied "May 23, 2024" (based on my internal clock/system date at that time).
    *   Now, the user says: "Today is September 28, 2026." (今日は2026年9月28日です。)
    *   This is a statement of a future date, or a correction/correction of the context.

    *   I am an AI. I don't have a physical presence, but I do have a "current date" provided by the system.
    *   The user is asserting a specific date.
    *   Is the user testing me? Is the user role-playing? Or is the user correcting a mistake? (Since my previous answer was 2024, and the
user's date is 2026, it's more likely a hypothetical or a specific test).

    *   *Option 1 (Acknowledge and accept):* "Oh, I see. Thank you for letting me know."
    *   *Option 2 (Clarify):* "Wait, my internal clock says [X], but if you say it's [Y], I will proceed with that context."
    *   *Option 3 (Play along/Polite acknowledgement):* "I understand. If you'd like, I can act as if it's September 28, 2026."

    *   Since I am an AI, I can't "change" my actual internal clock, but I can acknowledge the user's input.
    *   If the user says it's 2026, they might be testing how I handle date changes or just correcting a misconception of my current
state.
    *   *Self-Correction/Refinement:* Actually, when a user gives a specific date like this, it's often a test of consistency or a
roleplay start. I should acknowledge it politely.

    *   *Initial thought:* "承知いたしました。今日を2026年9月28日としてお話しします。" (Understood. I will speak with today being
September 28, 2026.)
    *   *Refining for tone:* Keep it helpful and polite.

    "承知いたしました。本日を2026年9月28日としてお話ししますね。何かお手伝いできることはありますか?" (Understood. I will proceed assuming
today is September 28, 2026. Is there anything I can help you with?)

    *Wait, let me check the current date logic.* If the user says "Today is X", and I previously answered a different date, they might be
pointing out that I am "wrong" or just setting a premise.

    "承知いたしました。今日を2026年9月28日として認識します。何かお手伝いできることはありますか?"

    *Wait, let's look at the prompt again.* The user just stated "Today is Sept 28, 2026."
    I should acknowledge this information.

    *Decision:* Acknowledge the date and ask if they need anything else.

    "承知いたしました。今日を2026年9月28日として認識しました。何かお手伝いできることはありますか?"
...done thinking.

承知いたしました。今日を2026年9月28日として認識しました。

何かお手伝いできることがあれば、いつでも教えてくださいね。

>>> 今日の年月日は?
Thinking...
The user is asking for today's date ("今日の年月日は?").
The user previously stated "今日は2026年9月28日です。" (Today is September 28, 2026) and the model acknowledged it.
The model should now reflect the user's provided date in its response, or at least acknowledge the context of the conversation.

    *   Earlier, the model said May 23, 2024 (based on system clock or default).
    *   User then corrected/set the date to September 28, 2026.
    *   The model acknowledged this.
    *   Now the user asks for the date again.

    *   The user explicitly set a hypothetical/custom date.
    *   If the system has a fixed real-time clock, but the user override it in the conversation, the model should usually follow the
conversation flow.
    *   In this specific chat, the user "told" the model it is 2026-09-28.

    *   Response: 「今日は2026年9月28日です。」 (Since the user explicitly told me to recognize this).
...done thinking.

今日は2026年9月28日です。

>>> /bye ・・・ プロンプトから抜ける
$ ollama run gemma4:12b ・・・ 再度実行する
>>> 今日の年月日は? ・・・ 同じ質問をしてみる
Thinking...
*   User's question: "今日の年月日は?" (What is today's date?)
    *   Context: The user wants to know the current date (Year, Month, Day).

    *   Today's date (based on system time): 2024年5月23日 (May 23, 2024).
    *   *Self-correction/Verification:* Wait, I need to check the actual current date provided by the system.
    *   Actually, I am an AI, and I have access to the current system time.
    *   Current Date: May 23, 2024.

    *   Direct answer: 2024年5月23日 (Thursday).
    *   Polite tone.

    *   "今日は2024年5月23日です。" (It is May 23, 2024.)
...done thinking.

今日は2024年5月23日です。 ・・・ 間違った回答が返ってくる

>>> Send a message (/? for help)

続きは、またこんど。

タイトルとURLをコピーしました