Overview
DSwitch is a cli tool that allows you to rapidly switch versions and channels of Dart.
DSwitch is a CLI tool that allows you to rapidly switch between channels and versions of Dart as well as running multiple version of Dart simultaneously.
If you are a flutter user then you are better of using FVM as FVM changes the version of dart embedded in Flutter.
DSwitch is intended to help manage a standalone version of Dart if you are doing things like building CLI applications.
For those interested, DSwitch is written Dart using the DCli API library.
DSwitch can switch between dart channels as well as versions within those channels.
The first time you try to switch between a channel or version, DSwitch will download and cache that channel/version. The next time you switch to the same channel or version the switch is almost instantaneous.
Sponsored by OnePub
Help support DSwitch by supporting OnePub, the private Dart repository.
OnePub allows you to privately share Dart packages across your Team and with your customers.
Try it for free and publish your first private package in seconds.
Publish a private package in five commands:
|
Installing DSwitch
To install DSwitch:
Windows users will need to run with Administrative privileges
How does DSwitch switch channels/versions?
DSwitch use a symbolically linked directory that you need to include in your PATH. When you switch versions or channels DSwitch simply re-links the path to the active version/channel.
For this mechanism to work you need to include the DSwitch active path to your PATH environment variable.
The active path is: <HOME>/.dswitch/active
Simultaneous version of Dart
DSwitch maintains a number of 'active' paths which you can uses in your IDE to select a specific version/channel of Dart.
The 'active' path points to the globally active version of Dart.
If you run 'dart' from the command line the 'active' version will be the one that runs.
There are also paths for each channel that points to the current version for that channel (see pinning below).
You can point your IDE at any of the above paths and then use DSwitch to manage the actual version used by a given channel.
Visual Code allows you to specify a per project path to the dart sdk.
You can also target a specific version of Dart without pinning it. The path for a specific Dart version is:
Dart Channels
DSwitch support moving between the following channels:
stable
beta
dev
From top to bottom, stable is the most reliable version of Dart and dev is the least reliable/bleeding edge version.
DSwitch commands
DSwitch uses the following command structure:
dswitch <channel> <action> <data>
DSwitch also supports a number of global actions which apply across channels. The command structure for global actions are:
dswitch <action> <data>
The following command switches to the beta channel
Command details
Channel commands
dswitch <channel> install [--select] <version>
Installs the given version for the given channel but does not switch to it.
If you don't provide a version then the latest version is installed.
If you pass the --select switch then a menu is displayed with a list of versions available for download.
dswitch <channel> list
List all of the locally cached version of Dart for the given channel.
dswitch <channel> upgrade
Upgrade the given channel to the latest version for that channel. This command will not switch channels. If the given channel is already active then dswitch will atomicly switch to the new version once it has been installed.
If the channel is pinned the upgrade action will have no affect, a warning will be displayed.
dswitch <channel> pin <version>
Selects the given version and channel and makes the selected version the current version for the channel.
You can only select a version that is cached locally. Use dswitch <channel> install
to download a version prior to pinning it.
Pinning does NOT activate the channel. Use dswitch switch <channel>
to activate the channel.
If you don't pass a version then a menu will be displayed with the list of locally cached versions for the channel to select from.
Pinning allows you to switch between version within a channel.
Use the unpin command to revert to the latest version for a channel.
dswitch <channel> unpin
Changes the channel to the latest locally cached version for the given channel.
Unpinning a channel does not change the active channel. If the the unpinned channel is the active channel then active channel will revert to the latest locally cached version.
Use dswitch <channel> upgrade
to download the latest version for the channel after unpinning it.
dswitch <channel> status
List the status of the channel such as:
The current version of the channel
Whether a later version is available for downloading.
Whether the channel is pinned
The version no. the channel is pinned to.
dswitch <channel> delete [--select] <version>
Deletes an old dart sdk version from the given channel.
If you pass the --select
switch then a menu of the installed versions is displayed. Select one of the versions to delete it.
You may not delete the active version.
Global Commands
dswitch use <channel>
Switch between channels. If the channel is not already downloaded, then the latest version for that channel will be downloaded and then DSwitch will switch to that channel.
If the channel is already downloaded then DSwitch will switch to the latest locally cached version for that channel.
dswitch status
Provides the same information as dswitch <channel> status
but for every channel.
dswitch list [--archive]
List all of the locally cached version of Dart for each channel.
If you pass the --archive flag it will list all of the versions available in the Dart online archive.
Last updated