DEV Community

Cover image for Building a Flutter Dev Environment on a Linux Server Without a GUI Environment
JH Jeong
JH Jeong

Posted on • Edited on

Building a Flutter Dev Environment on a Linux Server Without a GUI Environment

Flutter + Linux

Motivation

Currently, I am in an environment where I cannot use my personal PC and can only use public PC. Public PCs are virtually impossible to install and use multiple programs because the disk is formatted immediately upon reboot. In this situation, I looked up various ways to develop Flutter and succeeded in building an environment. I hope this article will help Flutter developers who are in a similar situation to me.

Sources

Basically, these are the posts I looked up.

Linux Server

I opened the server through Google Cloud Platform.
code-server + gcp
Ubuntu's version was 22.04 LTS and the disk size was set to 64GB.
I'm only going to use free credit anyway, so it doesn't matter if I set it up randomly.

Install Openjdk

$ sudo apt-get install openjdk-8-jdk
Enter fullscreen mode Exit fullscreen mode

Install open jdk.
It probably works without additional variable settings.

$ java
Enter fullscreen mode Exit fullscreen mode

Check if it is installed properly by typing the command above.

Install Flutter SDK

$ sudo snap install flutter --classic
Enter fullscreen mode Exit fullscreen mode

Download the Flutter SDK easily by typing the command above.
In the same environment as mine, the Flutter SDK will be installed in the following folder.
/home/{account name}/snap/flutter/common/flutter

Next, add environmental variables.
You may find .bashrc file in this directory.
/home/{account name}/.bashrc

Open it with vim.
$ vim .bashrc

Add the following to the bottom of the .bashrc file:

export PATH="$PATH:/home/<your account name>/snap/flutter/common/flutter/bin"
Enter fullscreen mode Exit fullscreen mode
$ source .bashrc
Enter fullscreen mode Exit fullscreen mode

Reload the shell by typing the command above.

$ flutter sdk-path
Enter fullscreen mode Exit fullscreen mode

Install cmdline tools

Create a folder with the following structure in the main working directory:

  • Android
    • cmdline-tools
      • latest

Then move the working directory to the 'latest' folder.
Cmdline-Tools
Download the cmdline-tools.zip file for Linux from the link above.
Upload the downloaded file to your Dropbox and create a download link.
At the end of the Dropbox link, There is a factor '?dl=0', which must be eliminated.
This is because the Linux shell does not recognize the '?' character.
Then copy the generated link and type:

$ wget <Link>
Enter fullscreen mode Exit fullscreen mode
$ unzip <filename.zip>
Enter fullscreen mode Exit fullscreen mode

Directory
If the structure like the picture above is made, it is a success.

Add the following to /home/{account name}/.bashrc:

export ANDROID_HOME="/home/<your account name>/Android"
export PATH="$PATH:$ANDROID_HOME/cmdline-tools/latest/bin/"
export PATH="$PATH:$ANDROID_HOME/emulator/"
export PATH="$PATH:$ANDROID_HOME/platform-tools/"
Enter fullscreen mode Exit fullscreen mode
$ source .bashrc
Enter fullscreen mode Exit fullscreen mode

Reload the shell by typing the command above.

$ sdkmanager --list
Enter fullscreen mode Exit fullscreen mode

Verify that it is added correctly through the command.

Install Packages

$ sdkmanager --install "platform-tools" "platforms;android-29" "build-tools;29.0.2" "emulator" "platforms;android-28" "build-tools;28.0.3"
Enter fullscreen mode Exit fullscreen mode

These are SDK packages that Flutter needs. If you enter the above command, it will be downloaded at once.

Flutter Android SDK Path

It should be set so that the path of the Android SDK can be found on the Flutter.

$ flutter config --android-sdk /home/<your account name>/Android
Enter fullscreen mode Exit fullscreen mode

Flutter Licenses

$ flutter doctor --android-licenses
Enter fullscreen mode Exit fullscreen mode

All you have to do is press y.

Install Chrome

$ wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
Enter fullscreen mode Exit fullscreen mode
$ sudo apt install ./google-chrome-stable_current_amd64.deb
Enter fullscreen mode Exit fullscreen mode

Install Android Studio

It cannot be used because there is no GUI environment anyway, but it only installs it.

$ sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386
Enter fullscreen mode Exit fullscreen mode
$ sudo add-apt-repository ppa:maarten-fonville/android-studio
Enter fullscreen mode Exit fullscreen mode

Conclusion

Perhaps if you have followed all of the above processes, it will be implemented without any problems.
Flutter Doctor
If you follow the above process but get an error, please add a comment.
Maybe I went through it, but I forgot and didn't upload it.
Good Luck Flutter Devs!

Top comments (0)