DEV Community

loading...
Cover image for How to get Visual Studio Code to run on Android with Termux

How to get Visual Studio Code to run on Android with Termux

codeledger profile image Morrison Chang Updated on ・2 min read

Termux is an app which provides a Unix/Linux-like environment on your Android device. But getting an familiar IDE like Visual Studio Code previous required a number of steps. Recently this seems to have been streamlined by the various package maintainers and now can be done in fewer steps.

First is that we will be installing the the open source version of Visual Studio Code (VS Code), called code-server.

code-server is an Electron app and needs support from nodejs environment.

In Termux run the following commands:

pkg install nodejs

pkg install yarn
Enter fullscreen mode Exit fullscreen mode

Per the Termux NodeJS wiki also install:

pkg install build-essential

pkg install python

pkg install git
Enter fullscreen mode Exit fullscreen mode

As they are needed for building native extensions.

And finally install code-server itself.

yarn global add code-server
Enter fullscreen mode Exit fullscreen mode

Note: Installing code-server will take a while

code-server is now installed and will be the back end server to your front end client, a Chromium browser, like Chrome for Android or Microsoft Edge.

Now from the command line run code-server or have it run in the background by adding an ampersand like code-server &.

code-server &
Enter fullscreen mode Exit fullscreen mode

You'll get some output logs about where the password is located.

In my case I used cat ~/.config/code-server/config.yaml to find out what was configured.

Open up a browser, as I was using Samsung DeX as a desktop, I used Samsung Internet, connected to 127.0.0.1:8080 and entered the password.

Screenshot_20201005-220244_Samsung Internet

Once connected, you can install plugins. As you can see, the MS Python plugin appears to work.

A few caveats:

Updating VS Code/code-server to latest (1.50.0)

Step 1: kill code-server if running

Step 2: Now update all of the packages (check above list)

pkg update
Enter fullscreen mode Exit fullscreen mode

Step 3: In order to force a rebuild, use yarn to remove code-server

yarn global remove code-server
Enter fullscreen mode Exit fullscreen mode

Step 4: And add/install code-server (yes it will take a while)

yarn global add code-server
Enter fullscreen mode Exit fullscreen mode

Getting Search to work

Thanks to yozman on this issue ticket

Install the package ripgrep:

pkg install ripgrep
Enter fullscreen mode Exit fullscreen mode

And add to the code-server directory

which is in my setup can be reached by:

cd /data/data/com.termux/files/home/.config/yarn/global/node_modules/code-server
Enter fullscreen mode Exit fullscreen mode

a softlink to the rg binary:

ln -s $PREFIX/bin/rg ./lib/vscode/node_modules/vscode-ripgrep/bin/rg
Enter fullscreen mode Exit fullscreen mode

Discussion

pic
Editor guide
Collapse
carlotamburin profile image
carlotamburin

When I install everything and type in the pass i get his error 500, and when i go home error 404. I tried dozens of ways to install android studio and only 2 way worked, installing not so latest 3.4.1 version with ubuntu and installing VHEditor from google store but with this I cannot install latest packages and extensions. Same goes with 3.4.1 version. I really want to set up my code server on tablet. Any help appreciated.

Collapse
codeledger profile image
Morrison Chang Author

Android Studio != VS Code. I haven't tried VHEditor so I don't know how well it works. What I described worked for me, but I also know that not all plugins and extensions will work. I also don't know what tablet you are using, running what version of Android, and how much free memory you have.

Collapse
carlotamburin profile image
carlotamburin

I am running on android 10, Samsung galaxy tab a7 10.4, 3GB of ram. The problem is that I can install the earlier version of code server 1.4.1 and I am running it now. But for example I couldn't install latest Python extension on it cause it says it needs newer version of visual code. So I manually downloaded VIX file of extension for my 1.4.1 version and it works. I am fine working on it but just wondering why I can't run the newest 1.5.0 version. I tried all possible methods on internet and only one worked for me and It's also from dev.to portal from publisher Josias Aurel. It method included installing ubuntu in terminal and using that method it works for me but no luck if I clone newer from the same github.

Thread Thread
codeledger profile image
Morrison Chang Author

Update my instructions above. You may have to 'yarn global remove' to make sure that code-server is built/linked against latest versions. But as of now I've got code-server VS Code 1.50.0 running on my Samsung Galaxy S9, Android 10 in Termux.