プログラミング

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

Windows 11にchocolateyをインストールし設定する方法と使い方について紹介します。Powershellにてインストールし、最後にテストとしてnode.jsをWindows 11にインストールし使えるようにします。他にもPythonやgit、Rubyなどのプログラミング言語や開発環境、ライブラリのインストールが可能です。

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にChocolateyをインストール

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

> choco --version
0.11.3

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

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

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

以下より、テストとして、chocoを使ってnode.jsをWindows 11にインストールしてみます。

get-command コマンドでnode.jsがインストールされていないことを確認します。

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

以下のコマンドで最新バージョンのnode.jsをインストールします。

> choco install nodejs -y
> choco install nodejs -y
Chocolatey v0.11.3
Installing the following packages:
nodejs
By installing, you accept licenses for the packages.
Progress: Downloading nodejs.install 17.0.1... 100%
Progress: Downloading nodejs 17.0.1... 100%

nodejs.install v17.0.1 [Approved]
nodejs.install package files install completed. Performing other installation steps.
Installing 64 bit version
Installing nodejs.install...
nodejs.install has been installed.
  nodejs.install may be able to 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 nodejs.install was successful.
  Software installed as 'msi', install location is likely default.

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

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

> echo $?
True

windows 11にnode.jsをインストール

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

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

> node -v
v17.0.1

node.jsでHello worldをしてみます。

> node -e 'console.log(`"Hello World...`")'
Hello World...

node.jsでHello world

なお、上記コマンドはpowershellで実行した場合です。WSL Bashやcmd.exeなどではエスケープシーケンスが異なるので、おそらくエラーになります。 (以下例)

[eval]:1
console.log(Hello World...)
            ^^^^^

SyntaxError: missing ) after argument list

コメントを残す

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