Mac安装Dart VSCode环境

作者: zmylw | 来源:发表于2019-10-31 16:07 被阅读0次

    一、安装Dart SDK

    Dart官方的安装教程步骤很简单两步,但实际安装过程还是没有那么容易!

     $ brew tap dart-lang/dart
     $ brew install dart
    

    执行第一条命令时,如下显示"Updating Homebrew..."很久,好吧更新brew,然后就是漫长的等待:

    $ brew tap dart-lang/dart
    Updating Homebrew...
    ==> Downloading https://homebrew.bintray.com/bottles-portable-ruby/portable-ruby--2.6.3.mavericks.bottle.tar.gz
    ######################################################################## 100.0%
    ==> Pouring portable-ruby--2.6.3.mavericks.bottle.tar.gz
    ==> Tapping dart-lang/dart
    Cloning into '/usr/local/Homebrew/Library/Taps/dart-lang/homebrew-dart'...
    remote: Enumerating objects: 6, done.
    remote: Counting objects: 100% (6/6), done.
    remote: Compressing objects: 100% (6/6), done.
    remote: Total 6 (delta 1), reused 1 (delta 0), pack-reused 0
    Unpacking objects: 100% (6/6), done.
    Tapped 3 formulae (33 files, 35.4KB).
    hc:~ hc$ brew install dart
    Updating Homebrew...
    Error: The following directories are not writable by your user:
    /usr/local/share/man/man8
    
    You should change the ownership of these directories to your user.
      sudo chown -R $(whoami) /usr/local/share/man/man8
    

    终于更新完了brew,然后报错:The following directories are not writable by your user:/usr/local/share/man/man8,看提示是没有读写权限,于是根据提示执行加权限的命令,继续安装:

    hc:~ hc$ sudo chown -R hc /usr/local/share/man/man8
    Password:
    hc:~ hc$ chmod u+w /usr/local/share/man/man8
    hc:~ hc$ brew install dart
    Updating Homebrew...
    ==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
      https://github.com/Homebrew/brew#donations
    ==> Auto-updated Homebrew!
    Updated 1 tap (homebrew/core).
    ==> New Formulae
    ………………
    ==> Installing dart from dart-lang/dart
    Error: Xcode alone is not sufficient on Mojave.
    Install the Command Line Tools:
      xcode-select --install
    

    继续报错:`Xcode alone is not sufficient on Mojave. Install the Command Line Tools,这是要安装Command Line Tools,根据提示安装Command Line Tools,此时会弹出安装对话框,一步一步往下就行。安装成功后继续安装Dart。

    hc:~ hc$ xcode-select --install
    xcode-select: note: install requested for command line developer tools
    hc:~ hc$ brew install dart
    Updating Homebrew...
    ==> Installing dart from dart-lang/dart
    ==> Downloading https://storage.googleapis.com/dart-archive/channels/stable/rele
    #######                                                                   100%
    ==> Caveats
    Please note the path to the Dart SDK:
      /usr/local/opt/dart/libexec
    ==> Summary
    

    Dart终于安装成功,使用--version命令可以看到版本号。使用brew info dart命令查看dart路径/usr/local/Cellar/dart/2.5.2,后面加上/bin配置环境变量:${PATH}:/usr/local/Cellar/dart/2.5.2/bin,保存后退出:

    hc:~ hc$ dart --version
    Dart VM version: 2.5.2 (Tue Oct 8 16:17:11 2019 +0200) on "macos_x64"
    hc:~ hc$ brew info dart
    dart-lang/dart/dart: stable 2.5.2, devel 2.6.0-dev.8.2
    The Dart SDK
    https://www.dartlang.org/
    /usr/local/Cellar/dart/2.5.2 (395 files, 559.2MB) *
      Built from source on 2019-10-31 at 15:22:38
    hc:~ hc$ vim ~/.bash_profile
    
    配置Dart环境变量

    二、安装VSCode

    1、安装VSCode

    安装好Dart环境,现在去VSCode官网下载安装IDE。

    安装VSCode
    2、安装Dart插件

    搜索Dart,选择安装


    安装Dart插件
    3、安装Code Runner插件

    搜索安装即可,安装后就可以运行Dart程序了 。


    安装Code Runner插件
    4、编写程序运行
    main() {
      print("Hello, World!");
    }
    
    编写程序运行
    运行程序看到“Hello, World!”了,到此可以开始Dart学习之旅了。要注意一下,必须先安装好Dart环境,再去安装VSCode,否则在VSCode里面会没有Dart语法提示,并且无法运行程序

    相关文章

      网友评论

        本文标题:Mac安装Dart VSCode环境

        本文链接:https://www.haomeiwen.com/subject/tubbattx.html