Building a Flutter Dev Environment on a Linux Server Without a GUI Environment
Tags: flutter, linux, ubuntu, tutorial
Published: 2022-08-16 06:19:00


![Flutter + Linux](https://velog.velcdn.com/images/edge/post/5b0ff768-29a8-48fd-aabd-880f0f590105/image.jpg)

## 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.
* [How to setup Android SDK without Android Studio.](https://proandroiddev.com/how-to-setup-android-sdk-without-android-studio-6d60d0f2812a)
* [Install Flutter SDK on windows without Android Studio](https://medium.com/@quicky316/install-flutter-sdk-on-windows-without-android-studio-102fdf567ce4)
* [LinuxBrew(HomeBrew) Install (Ubuntu 18.04)](https://www.whatwant.com/entry/LinuxBrew-install-Ubuntu-1804)
* [code-server + gcp](https://yeoularu.tistory.com/10)
* [Install Chrome in Linux](https://www.lesstif.com/lpt/linux-chrome-106857342.html)
* [Ubuntu Install Android Studio](https://coding-factory.tistory.com/503)

## Linux Server
I opened the server through Google Cloud Platform.
[code-server + gcp](https://yeoularu.tistory.com/10)
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
```
Install open jdk.
It probably works without additional variable settings.
```
$ java
```
Check if it is installed properly by typing the command above.


## Install Flutter SDK 
```
$ sudo snap install flutter --classic
```
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"
```
```
$ source .bashrc
```
Reload the shell by typing the command above.
```
$ flutter sdk-path
```


## 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](https://developer.android.com/studio#command-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>
```
```
$ unzip <filename.zip>
```
![Directory](https://velog.velcdn.com/images/edge/post/120e3482-8071-4543-b9b4-6ace7f751622/image.png)
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/"
```

```
$ source .bashrc
```
Reload the shell by typing the command above.

```
$ sdkmanager --list
```
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"
```
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
```

## Flutter Licenses
```
$ flutter doctor --android-licenses
```
All you have to do is press y.

## Install Chrome
```
$ wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
```
```
$ sudo apt install ./google-chrome-stable_current_amd64.deb
```

## 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
```

```
$ sudo add-apt-repository ppa:maarten-fonville/android-studio
```

## Conclusion
Perhaps if you have followed all of the above processes, it will be implemented without any problems.
![Flutter Doctor](https://velog.velcdn.com/images/edge/post/77c5860d-0515-41e4-9f76-86a019c8e0ac/image.png)
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!