Setting Up Flutter and Dart on a Linux Server / VPS ( Debian/Ubuntu / Red Hat/Alma/Rocky/CentOs )

Amin
mabttech
Published in
4 min readMay 9, 2024

Setting up your development environment correctly on an Ubuntu server is crucial for productivity and efficiency, especially when working with powerful frameworks and tools like Flutter and Dart. This guide will walk you through the steps of adding Flutter and Dart to your ~/.bashrc file on an Ubuntu server, ensuring that these tools are easily accessible from your command line.

Flutter & dart on ubuntu / Linux

Why Add Flutter and Dart to ~/.bashrc?

Adding environment variables to your ~/.bashrc file ensures that they are set up automatically every time a new shell session is started. This saves you the trouble of having to manually configure these settings each time you log in to your server, and it ensures consistency across your working sessions.

Prerequisites

  • Ubuntu Server: This guide assumes you are using Ubuntu 20.04 LTS, but the instructions should be similar for other versions.
  • Flutter and Dart Installed: Ensure that Flutter is installed on your Ubuntu server. Typically, Flutter includes the Dart SDK, so separate Dart installation is not necessary.

Downloading Flutter in Linux Server / VPS ( Debian/Ubuntu / Red Hat/Alma/Rocky/CentOs / Vagrant VM )

( you can checkout this tuto for more details in the related links down below )

I chose my version 3.19.6-stable :

select your version and copy the path/link

For Debian/Ubuntu ( use sudo apt ) :

sudo apt update 

sudo apt install -y git wget unzip curl xz-utils

For Red Hat/Alma/Rocky/CentOs ( use sudo yum ) :

sudo yum install -y git wget unzip

curl -O https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_3.19.6-stable.tar.xz

tar xf flutter_linux_3.19.6-stable.tar.xz

sudo mv flutter /opt/flutter

After finishing the installation you can delete the compressed file :

After installation, you can clean up by removing the downloaded archive to save space.

rm -R flutter_linux_3.19.6-stable.tar.xz
  • Set up Flutter environment variables: Once the download is complete, you'll need to set up the necessary environment variables to use the Flutter SDK.
  • a. Add the Flutter SDK directory to the PATH environment variable. Run the following command to open the shell configuration file (e.g., .bashrc, .zshrc, or .profile, depending on the shell being used):

nano ~/.bashrc

b. Add the following line at the end of the file:

export PATH="$PATH:/path/to/flutter/bin"

Step 1: Locate the Flutter Installation

Confirm the location of your Flutter installation. Commonly, it might be installed in /opt/flutter. This directory should contain the bin folder which holds the executable files for Flutter and Dart.

ls -als /opt/flutter/bin

You should see flutter and possibly dart listed among other files.

Step 2: Open Your ~/.bashrc File

Open your ~/.bashrc file using a text editor. Here, we'll use nano, but you can use any text editor like vim or gedit.

nano ~/.bashrc

Step 3: Set Environment Variables

Scroll to the end of the file and add the following lines to set FLUTTER_HOME and DART_HOME, and update the PATH variable:

# Flutter & Flutter bin Path
export PATH="$PATH:/opt/flutter/bin"


# Set Flutter and Dart Home
export FLUTHER_HOME=/opt/flutter
export DART_HOME=$FLUTTER_HOME/bin
# Update PATH
export PATH=$DART_HOME:$PATH

Add the following lines at the end of the file [add all of these to the end of ~/.bashrc ]:

# Set Flutter and Dart Home
export FLUTTER_HOME=/opt/flutter
export DART_HOME=$FLUTTER_HOME/bin
# Update PATH
export PATH=$DART_HOME:$PATH

These commands set the home directories for both Flutter and Dart and add Dart’s bin directory to the system path, allowing you to run Flutter and Dart commands from any terminal window.

Step 4: Apply the Changes

After saving your changes in the ~/.bashrc file (use CTRL+O and CTRL+X to save and exit in nano), apply the changes by sourcing the ~/.bashrc file:

source ~/.bashrc

Step 5: Verify the Installation

To ensure that everything is set up correctly, you can verify the installation by checking the versions of Flutter and Dart:

flutter --version
dart --version

This will display the installed versions of Flutter and Dart, confirming that they are correctly set up and accessible.

Conclusion

Congratulations! You’ve successfully configured your Ubuntu server to automatically set up Flutter and Dart every time you start a new shell session. This setup not only streamlines your development process but also ensures that you have consistent environment settings across sessions.

Further Resources

For more information on Flutter and Dart, you can visit the official Flutter website at Flutter and the Dart website at Dart.

Remember, a well-configured development environment is key to efficient and enjoyable software development. Happy coding!

Related Tuto / Links :

https://buymeacoffee.com/mabttech
https://buymeacoffee.com/mabttech

--

--