LoginSignup
3
2

[Flutter] fvm インストールまでの道のり

Posted at

はじめに

ただ Flutter fvm インストールしたいだけなのに
なかなかゴールにたどり着けなかったのでその軌跡をまとめておきます。
Flutter初級者のため、情報に誤りがある可能性がございます。ご了承ください。

前提

Flutter SDKを事前にインストールしておく

Dart SDKのインストール

  1. Dartのリポジトリをbrewで登録する

    • brew tap コマンドは、Homebrewで提供されているサードパーティのリポジトリを登録するためのコマンド。このコマンドにより、パッケージを検索してインストールできるようなる
    • Dart言語の公式パッケージがHomebrewに登録され、Dart SDKをHomebrewを使用して簡単にインストールすることができるようになる
    brew tap dart-lang/dart
    
  2. Dart SDKのインストール

    brew install dart
    

    → エラー発生
    コマンドラインツールがないためインストールしろと言われる

    Error: Xcode alone is not sufficient on Monterey.
    Install the Command Line Tools:
      xcode-select --install
    
  3. Xcodeコマンドラインツールのインストール (command line developer tools)

    xcode-select --install
    

    clt.png

    • Xcodeコマンドラインツールが正しくインストールされたか以下で確認
      xcode-select -p
      
      /Applications/Xcode.app/Contents/Developer
      
  4. 再度、2.の項目でDart SDKをインストールする

  5. Dart SDK がインストールされたか?確認する

    dart --version
    
    Dart SDK version: 2.16.2 (stable) (Tue Mar 22 13:15:13 2022 +0100) on "macos_x64"
    

fvmのインストール

  1. fvmをグローバルにインストールする

    • pubとはDartのパッケージ管理ツールのこと
    • 以下を実行してもfvmにPATHが通っていないためパスを通す必要がある
    • ※ インストールが正しくできない場合
      dart pub global activate fvm頭にdart 〜をつけてコマンドしてみる
      (pub コマンドは非推奨のため、 dart pub 〜 コマンドで実行する)
      pub global activate fvm
      
      → pub command not found
      
  2. fvmへのパスを通す

    • .zshrc に以下を追記する

      export PATH="$PATH":"$HOME/.pub-cache/bin"
      
    • .zshrcを再設定する

      source ~/.zshrc
      
    • fvmへパスが通っているか確認する バージョンがでたら正しくインストールできている

      fvm --version
      
      2.4.1
      
    • fvm —version で、以下のエラーが出る場合
      dart pub global activate fvm を実行してみる

      Can't load Kernel binary: Invalid kernel binary format version.
      Could not find a file named "pubspec.yaml" in "/Users/ユーザー名/.pub-cache/hosted/pub.dev/fvm-2.3.1".
      
    • それでもうまくできない場合
      which dart でDartSDKのインストールパスを確認する

      which dart
      
      /Users/ユーザー名/development/flutter/bin/dart
      
  3. dart-sdk/bin ディレクトリを$PATH 環境変数に追加する
    .zshrc に以下を追加
    インストールパスはwhich dart で出たパスを記述

    export PATH="$PATH:/Users/ユーザー名/development/flutter/bin/cache/dart-sdk/bin"
    

参考

3
2
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
3
2