0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

環境設定ツール - mise

0
Last updated at Posted at 2025-11-21

概要

(日記)環境設定ツール miseを試す
プロジェクトごとに、環境(使用ツール・環境変数)を切り替えたい場合有用。
ある程度Windows/Linux共通の環境を構築できる。頻繁にwslで切り替えるなら必須。
他にも、スクリプト定義、CLIでのalias(Linux)など。

環境

  • Windows 11(PowerShell 7.5.4) / Ubuntu24.04

導入

  • mise: 2026.7.0
Ubuntu 24.04 // 公式
curl https://mise.run | sh
~/.bashrc 末尾に追加
eval "$(~/.local/bin/mise activate bash)"
export PATH="$HOME/.local/share/mise/shims:$PATH"

インストール場所(bash): ~/.local/bin/mise

Windows - PowerShell
Windows 11
winget install jdx.mise

notepad $PROFILE

$PROFILE に下記を追記
mise activate pwsh | Out-String | Invoke-Expression
$env:PATH = "$HOME\.local\share\mise\shims;" + $env:PATH
もしくは
New-Item -ItemType Directory -Force (Split-Path $PROFILE); Add-Content $PROFILE "mise activate pwsh | Out-String | Invoke-Expression"
Windows ps1を実行できない
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Windows Proxy
#proxy設定
$ProxyUri = "http://user:pass@host:port"
$Env:HTTP_PROXY = $ProxyUri
$Env:HTTPS_PROXY = $ProxyUri
その他のインストール関連
Ubuntu 24.04 - aptでinstallしたい
sudo apt update -y && sudo apt install -y gpg sudo wget curl
sudo install -dm 755 /etc/apt/keyrings
wget -qO - https://mise.jdx.dev/gpg-key.pub | gpg --dearmor | sudo tee /etc/apt/keyrings/mise-archive-keyring.gpg 1> /dev/null
echo "deb [signed-by=/etc/apt/keyrings/mise-archive-keyring.gpg arch=amd64] https://mise.jdx.dev/deb stable main" | sudo tee /etc/apt/sources.list.d/mise.list
sudo apt update
sudo apt install -y mise
Ubuntu 24.04 // docker-rootless環境なら楽
alias mise.dk='docker run --rm jdxcode/mise'
mise.dk version # バージョン確認
Mac // 未確認
brew install mise

使用

とりあえず使用例
mise use    java             # mise上にjavaをインストールし、このプロジェクト使用
mise use -g java             # mise上にjavaをインストールし、このユーザとして使用
mise unuse  java             # このプロジェクトでjava不使用。miseからアンインストールしない。
mise uninstall java          # miseからjavaをアンインストール。

mise set    EDITOR=vim       # このプロジェクトで環境変数EDITORを"vim"に設定 
mise set -g EDITOR=emacs     # このユーザとして環境変数EDITORを"emacs"に設定 
mise unset  EDITOR           # このプロジェクトの環境変数EDITORを未定義に設定 

mise trust                   # 新規mise.tomlファイルを信頼する
mise doctor                  # Version/Backend/Plugin/Toolset等確認
mise ls                      # インストール済みToolリスト
mise ls-remote --all         # インストール可能なTool/Versionを列挙
mise p ls-remote             # 使用可能Pluginリスト
能にする
mise self-update             # mise自体を更新
mise up                      # Toolを更新

ユーザ設定(-g)は、 ~/.config/mise/config.toml に、
プロジェクト設定は最も近いmise.tomlに格納される。

Windows - `%LOCALAPPDATA%\mise` : mise管理ファイル(Tools等) - `%USERPROFILE%\.config\mise\config.toml` : User共通設定 - `.\mise.toml` : プロジェクト設定

削除

mise 自体を削除したら miseでinstallしたToolsも削除される。
mise doctor の dirsで表示される関連ディレクトリを削除。
.bashrcなどに追記した mise activate の設定を削除

Windows 設定 > アプリ から削除

設定

設定ファイル(mise.toml等)の配置場所(優先順):

  • ./ / ./.config/ / ../.../ / ../.../.config/ : プロジェクト設定(*1)
  • ~/.config/mise/ : ユーザ設定
  • /etc/mise/ : システム設定

直近の親ディレクトリの設定が優先。
shell上でカレントディレクトリを移動することで、プロジェクト切り替え可能。

設定ファイル種別(優先順):

  • mise.{MISE_ENV}.local.toml : コミットNGな環境依存設定(*2)
  • mise.local.toml:コミットNGな設定]
  • mise.{MISE_ENV}.toml : 環境依存設定(*2)
  • mise.toml : 設定情報
  • ~/.config/mise/config.toml : ユーザ設定

*1: mise.*.mise.*も可。 両方あれば.mise.* が優先
*2: (メタ設定) mise.{MISE_ENV}.tomlファイルのうちどれを参照するかは 環境変数MISE_ENVおよび.miserc.tomlファイルのenv設定で指定できる。
.miserc.tomlファイルの場所は以下の順に参照。設定は継承されない。

  • ./.miserc.toml, ./.config/miserc.toml : プロジェクト設定
  • ~/.config/mise/miserc.toml: ユーザ設定
  • /etc/mise/miserc.toml : システム設定

例: 環境変数MISE_ENV="linux,env1"を指定、miserc.tomlにenv=["env2"]を記載した場合、参照するファイルはmise.linux.toml,mise.env1.toml,mise.env2.tomlとなる。

Case. 暗号化

秘密情報を含むmise設定ファイルを暗号化したい。

(例) .config/mise.keys.toml を暗号化
mise use -g sops age # 
age-keygen -o .config/mise/age.txt
# 公開鍵: .config/mise/age.txt のヘッダーコメント内に記載されている age1から始まる文字列
sops encrypt -i --age age1uqwzzv6f3sy070ycz27e6xh2ljp7v62rsn89jez3kkxa2vd79qqqk884e9 .config/mise.keys.toml
./mise.toml
[tools]
sops = "latest"
age = "latest"
[env]
HOME={default="{{env.USERPROFILE}}"}
SOPS_AGE_KEY_FILE=".config/mise/age.txt"
[tasks]
mise-age-keygen = "age-keygen -o .config/mise/age.txt"
mise-enc-replace = { run = "sops encrypt -i", dir = "{{cwd}}" }
mise-dec-replace = { run = "sops decrypt -i", dir = "{{cwd}}" }

Case. ツール導入

miseで定義された各ツールを使用できる

./mise.toml
[tools]
node = "lts"
opencode = "latest"
"http:neo4j" = { version = "5.26.0", url = "https://dist.neo4j.org/neo4j-community-{{version}}-windows.zip" }

Case. 環境変数

環境変数を定義できる。
カレントディレクトリに応じて設定できる。
MISE_ENVや.miserc.tomlでの指定やOSに応じて設定できる。

./.miserc.toml - miseメタ設定
env = ["pxy1"]
auto_env = true # OS情報をenvに自動設定。mise 2026.7.0 ではデフォルトfalse
./mise.toml - 公開可能な情報
[env]
PXY_USER = "user-name"
./mise.pxy1.local.toml - 公開不可能な情報。
[env]
PXY_PASS = "********"
./mise.pxy1.toml
[env]
HTTP_PROXY = "http://{{env.PXY_USER}}:{{env.PXY_PASS}}@proxy.domain:8080"
HTTPS_PROXY = "http://{{env.PXY_USER}}:{{env.PXY_PASS}}@proxy.domain:8080"
./mise.windows.toml - WindowsでのHOME定義
[env]
MISE_HOME = "{{env.USERPROFILE}}"
./mise.linux.toml - LinuxでのHOME定義
[env]
MISE_HOME = "{{env.HOME}}"

Case. タスク

TODO

Tips: shell-aliasのようにtasksを実行

shell-alias機能は有用だが、現状(v2026.8.0)PowerShell非対応。
PowershellのAliasコマンドでmiseから実行するとしても実行中のシェルを動的に変更することは困難そう。考えた末..
これでxxxとタイプすればmiseのタスクmise run xxxが実行される。
⚠️デフォルトでタスクはmiseのプロジェクトディレクトリで実行される。カレントディレクトリで実行したい場合、tasks設定で dir={{cwd}} を追記。

~/.bashrc に追記
    command_not_found_handle() {
        mise run "$@"
    }
~\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 ($PROFILE) に追記
$ExecutionContext.InvokeCommand.CommandNotFoundAction = {
    param($commandName, $eventArgs)
    $tasks = mise tasks --json | ConvertFrom-Json
    $match = $tasks | Where-Object { $_.name -eq $commandName -or $_.aliases -contains $commandName }
    if ($match) {
        $safe = $commandName -replace "'", "''"
        $eventArgs.CommandScriptBlock = [scriptblock]::Create("mise run '$safe' @args")
        $eventArgs.StopSearch = $true
    }
}
full
~\Documents\PowerShell\Microsoft.PowerShell_profile.ps1
mise activate pwsh | Out-String | Invoke-Expression

# mise タスク用 CommandNotFoundAction
$ExecutionContext.InvokeCommand.CommandNotFoundAction = {
    param($commandName, $eventArgs)
    $tasks = mise tasks --json | ConvertFrom-Json
    $match = $tasks | Where-Object { $_.name -eq $commandName -or $_.aliases -contains $commandName }
    if ($match) {
        $safe = $commandName -replace "'", "''"
        $eventArgs.CommandScriptBlock = [scriptblock]::Create("mise run '$safe' @args")
        $eventArgs.StopSearch = $true
    }
}

# mise run <task> のタブ補完
Register-ArgumentCompleter -Native -CommandName mise -ScriptBlock {
    param($wordToComplete, $commandAst, $cursorPosition)
    $words = $commandAst.ToString().Trim() -split '\s+'
    if ($words.Count -ge 2 -and $words[1] -eq 'run') {
        foreach ($t in (mise tasks --json | ConvertFrom-Json)) {
            if ($t.name -like "$wordToComplete*") {
                $desc = if ($t.description) { $t.description } else { $t.name }
                [System.Management.Automation.CompletionResult]::new($t.name, $t.name, 'ParameterValue', $desc)
            }
            foreach ($a in $t.aliases) {
                if ($a -like "$wordToComplete*") {
                    [System.Management.Automation.CompletionResult]::new($a, $a, 'ParameterValue', "Alias: $($t.name)")
                }
            }
        }
    }
}

# mise タスクプロキシ関数の登録
foreach ($t in (mise tasks --json | ConvertFrom-Json)) {
    $safe = $t.name -replace "'", "''"
    Set-Item "function:global:$safe" ([scriptblock]::Create("mise run '$safe' @args"))
    foreach ($a in $t.aliases) {
        $safeA = $a -replace "'", "''"
        Set-Item "function:global:$safeA" ([scriptblock]::Create("mise run '$safeA' @args"))
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?