DEV Community

Cover image for How to get Visual Studio Code to run on Android with Termux
Morrison Chang
Morrison Chang

Posted on • Updated on

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

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 (14)

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 • Edited on

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.

Collapse
essounstephen787845 profile image
Stephen Essoun

I have tried and tried several times and I am still having the same error.
I have run different codes from different source and still not opening

Collapse
steledama profile image
Stefano Pompa

it seems wonderfull. Unfurtunately at the moment i receive this error:
code-server@3.12.0: The engine "node" is incompatible with this module. Expected version "= 14". Got "16.13.1"

Collapse
malius11 profile image
Malius

Same thing here. Did u manage to make it work?

Collapse
steledama profile image
Stefano Pompa

unfurtunately no!

Thread Thread
nimbuldev profile image
nimbul

You should just need to install version 14.x of Node. I'm not sure how to do this with a termux pkg, you'll have to dig.

I installed nvm and ran source /usr/share/nvm/init.nvm.sh and nvm install 14 on my proot Arch, not sure if that'll help you!

Collapse
saeedmfarahani profile image
Saeed M Farahani

yarn global v1.22.18
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
warning "code-server > @coder/logger@1.1.16" has unmet peer dependency "@google-cloud/logging@^4.5.2".
[4/4] Building fresh packages...
[1/3] ⠄ argon2
[-/3] ⡀ waiting...
error /data/data/com.termux/files/home/.config/yarn/global/node_modules/argon2: Command failed.
Exit code: 1
Command: node-pre-gyp install --fallback-to-build
Arguments:
Directory: /data/data/com.termux/files/home/.config/yarn/global/node_modules/argon2
Output:
node-pre-gyp info it worked if it ends with ok
node-pre-gyp info using node-pre-gyp@1.0.9
node-pre-gyp info using node@16.14.2 | android | arm
node-pre-gyp info check checked for "/data/data/com.termux/files/home/.config/yarn/global/node_modules/argon2/lib/binding/napi-v3/argon2.node" (not found)
node-pre-gyp http GET github.com/ranisalt/node-argon2/re...
node-pre-gyp ERR! install response status 404 Not Found on github.com/ranisalt/node-argon2/re...
node-pre-gyp WARN Pre-built binaries not installable for argon2@0.28.5 and node@16.14.2 (node-v93 ABI, unknown) (falling back to source compile with node-gyp)
node-pre-gyp WARN Hit error response status 404 Not Found on github.com/ranisalt/node-argon2/re...
gyp info it worked if it ends with ok
gyp info using node-gyp@8.4.1
gyp info using node@16.14.2 | android | arm
gyp info ok
gyp info it worked if it ends with ok
gyp info using node-gyp@8.4.1
gyp info using node@16.14.2 | android | arm
gyp info find Python using Python version 3.10.4 found at "/data/data/com.termux/files/usr/bin/python3"
gyp http GET nodejs.org/download/release/v16.14...
gyp http 200 nodejs.org/download/release/v16.14...
gyp http GET nodejs.org/download/release/v16.14...
gyp http 200 nodejs.org/download/release/v16.14...
gyp info spawn /data/data/com.termux/files/usr/bin/python3
gyp info spawn args [
gyp info spawn args '/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'make',
gyp info spawn args '-I',
gyp info spawn args '/data/data/com.termux/files/home/.config/yarn/global/node_modules/argon2/build/config.gypi',
gyp info spawn args '-I',
gyp info spawn args '/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args '-I',
gyp info spawn args '/data/data/com.termux/files/home/.cache/node-gyp/16.14.2/include/node/common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=/data/data/com.termux/files/home/.cache/node-gyp/16.14.2',
gyp info spawn args '-Dnode_gyp_dir=/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/node-gyp',
gyp info spawn args '-Dnode_lib_file=/data/data/com.termux/files/home/.cache/node-gyp/16.14.2/<(target_arch)/node.lib',
gyp info spawn args '-Dmodule_root_dir=/data/data/com.termux/files/home/.config/yarn/global/node_modules/argon2',
gyp info spawn args '-Dnode_engine=v8',
gyp info spawn args '--depth=.',
gyp info spawn args '--no-parallel',
gyp info spawn args '--generator-output',
gyp info spawn args 'build',
gyp info spawn args '-Goutput_dir=.'
gyp info spawn args ]
gyp info ok
gyp info it worked if it ends with ok
gyp info using node-gyp@8.4.1
gyp info using node@16.14.2 | android | arm
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
make: Entering directory '/data/data/com.termux/files/home/.config/yarn/global/node_modules/argon2/build'
CC(target) Release/obj.target/libargon2/argon2/src/ref.o
CC(target) Release/obj.target/libargon2/argon2/src/argon2.o
CC(target) Release/obj.target/libargon2/argon2/src/core.o
CC(target) Release/obj.target/libargon2/argon2/src/blake2/blake2b.o
CC(target) Release/obj.target/libargon2/argon2/src/thread.o
CC(target) Release/obj.target/libargon2/argon2/src/encoding.o
AR(target) Release/obj.target/argon2.a
/data/data/com.termux/files/usr/bin/sh: 1: ar: not found
make: *** [libargon2.target.mk:149: Release/obj.target/argon2.a] Error 127
make: Leaving directory '/data/data/com.termux/files/home/.config/yarn/global/node_modules/argon2/build'
gyp ERR! build error
gyp ERR! stack Error: make failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack at ChildProcess.emit (node:events:526:28)
gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
gyp ERR! System Linux 4.14.133
gyp ERR! command "/data/data/com.termux/files/usr/bin/node" "/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--module=/data/data/com.termux/files/home/.config/yarn/global/node_modules/argon2/lib/binding/napi-v3/argon2.node" "--module_name=argon2" "--module_path=/data/data/com.termux/files/home/.config/yarn/global/node_modules/argon2/lib/binding/napi-v3" "--napi_version=8" "--node_abi_napi=napi" "--napi_build_version=3" "--node_napi_label=napi-v3"
gyp ERR! cwd /data/data/com.termux/files/home/.config/yarn/global/node_modules/argon2
gyp ERR! node -v v16.14.2
gyp ERR! node-gyp -v v8.4.1
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute '/data/data/com.termux/files/usr/bin/node /data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/data/data/com.termux/files/home/.config/yarn/global/node_modules/argon2/lib/binding/napi-v3/argon2.node --module_name=argon2 --module_path=/data/data/com.termux/files/home/.config/yarn/global/node_modules/argon2/lib/binding/napi-v3 --napi_version=8 --node_abi_napi=napi --napi_build_version=3 --node_napi_label=napi-v3' (1)
node-pre-gyp ERR! stack at ChildProcess. (/data/data/com.termux/files/home/.config/yarn/global/node_modules/@mapbox/node-pre-gyp/lib/util/compile.js:89:23)
node-pre-gyp ERR! stack at ChildProcess.emit (node:events:526:28)
node-pre-gyp ERR! stack at maybeClose (node:internal/child_process:1092:16)
node-pre-gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5)
node-pre-gyp ERR! System Linux 4.14.133
node-pre-gyp ERR! command "/data/data/com.termux/files/usr/bin/node" "/data/data/com.termux/files/home/.config/yarn/global/node_modules/argon2/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /data/data/com.termux/files/home/.config/yarn/global/node_modules/argon2
node-pre-gyp ERR! node -v v16.14.2
node-pre-gyp ERR! node-pre-gyp -v v1.0.9
node-pre-gyp ERR! not ok
Failed to execute '/data/data/com.termux/files/usr/bin/node /data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/data/data/com.termux/files/home/.config/yarn/global/node_modules/argon2/lib/binding/napi-v3/argon2.node --module_name=argon2 --module_path=/data/data/com.termux/files/home/.config/yarn/global/node_modules/argon2/lib/binding/napi-v3 --napi_version=8 --no

Collapse
iamaniket profile image
Aniket Kumar

Sir i'm unable to login. I couldn't find my password it say password us in ~/.config/code-server/config.yaml

Collapse
youralmight profile image
youralmight

Much help. It works for me and now I can play on my phone freely.

Collapse
ferseinchris profile image
FerseinChris

This is here the issue I'm meeting, please can you tell me how to fix this ?

Collapse
essounstephen787845 profile image
Stephen Essoun

I am getting stacked in my class due that I have no laptop so please try and help me
I am using Techno Spark 4
Is it possible or not? Because I've tried severally. Thank You.