プログラミング

Windows 11にGitをインストールする

Windows 11にGitをインストールし設定する方法と使い方について紹介します。Powershellからchocolateyを使ってインストールします。Gitはプログラミングにおいて、チームでの作業に限らず必需品であり、また普段の仕事で使う場合でも便利なソフトウェアです。

この記事ではGitをchocolateyを利用してインストールします。

chocoではWindowsおよびWindows 11において、プログラミング言語・開発環境やライブラリ、ソフトウェアなどがプログラミングにおいて使用する様々なプログラムやユーティリティソフトウェアを、ショートカットでインストールできます。
chocoの使い方を知っていれば、PythonやRubyのようなプログラミング言語をインストールする方法を都度調べなくても、chocoのウェブサイトのデータベースからインストールしたいプログラムを確認し、それをコマンドすることで面倒なインストール、環境変数パスの設定などを含め、自動でインストールを完了できます。

Windows 11にchocolateyをインストールします。管理者権限でPowershellを開いて、以下のコマンドを実行します。
なお、管理者権限のPowershellはタスクバーのpowershellアイコンを右クリック、さらに右クリック、”管理者権限として実行”を選択します。

> Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

以下のように表示されていればインストールが正常に完了しています。

“Chocolatey (choco.exe) is now ready”

windows 11にchocoをインストール

インストールが確実かどうかは、バージョンを出力させてみることでわかります。

> choco --version
0.11.3

refreshenvコマンドを実行します。

> refreshenv
Refreshing environment variables from registry for cmd.exe. Please wait...Finished..

この時点でchocoで利用可能な様々なプログラミング言語・開発環境やライブラリ、ソフトウェアなどがインストール可能となっています。

以下より、chocoを使ってGitをインストールします。

以下コマンドでGitをインストールします。

> choco install git -y
> choco install git -y
Chocolatey v0.11.3
Installing the following packages:
git
By installing, you accept licenses for the packages.
Progress: Downloading git.install 2.33.1... 100%
Progress: Downloading chocolatey-core.extension 1.3.5.1... 100%
Progress: Downloading git 2.33.1... 100%

chocolatey-core.extension v1.3.5.1 [Approved]
chocolatey-core.extension package files install completed. Performing other installation steps.
 Installed/updated chocolatey-core extensions.
 The install of chocolatey-core.extension was successful.
  Software installed to 'C:\ProgramData\chocolatey\extensions\chocolatey-core'

git.install v2.33.1 [Approved]
git.install package files install completed. Performing other installation steps.
Using Git LFS
Installing 64-bit git.install...
git.install has been installed.
WARNING: Can't find git.install install location
  git.install can be automatically uninstalled.
Environment Vars (like PATH) have changed. Close/reopen your shell to
 see the changes (or in powershell/cmd.exe just type `refreshenv`).
 The install of git.install was successful.
  Software installed to 'C:\Program Files\Git\'

git v2.33.1 [Approved]
git package files install completed. Performing other installation steps.
 The install of git was successful.
  Software install location not explicitly set, it could be in package or
  default install location of installer.

Chocolatey installed 3/3 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

> echo $?
True

windows 11にgitをインストール

この時点でGitのインストールは完了していますが、注意点として、コンソールを再起動しなければコマンドが使えるようになりません。
例えばpowershell.exeを起動しているならそのウィンドウを閉じ、もう一度新しく開きます。conemuならconemuを閉じ、新しく開きます。あるいは新しいインスタンスを開いても問題ありません。

同じコンソールウィンドウで実行した場合、以下のようにエラーになります。

> git -v
git : 用語 'git' は、コマンドレット、関数、スクリプト ファイル、または操作可能なプログラムの名前として認識されません。
名前が正しく記述されていることを確認し、パスが含まれている場合はそのパスが正しいことを確認してから、再試行してください
。

新しいインスタンスのコンソールのコマンドライン上で、以下コマンドにてGitのバージョンを確認します。

> git --version
git version 2.33.1.windows.1

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です