Skip to content

Instantly share code, notes, and snippets.

@ppoffice
Last active March 18, 2024 02:44
Show Gist options
  • Save ppoffice/b9e88c9fd1daf882bc0e7f31221dda01 to your computer and use it in GitHub Desktop.
Save ppoffice/b9e88c9fd1daf882bc0e7f31221dda01 to your computer and use it in GitHub Desktop.
Install Visual Studio Code (actually code-server) on Android
  1. Install Termux, an Android terminal emulator that provides a Linux execution environment and various tools.

  2. Update system packages in Termux:

    $ pkg update -y
  3. Install dependencies, including python, nodejs, and yarn:

    $ pkg install -y python nodejs yarn git
  4. Install code-server, an adaptation of Visual Studio Code that runs as a web app using the following command. The installation may take a while:

    $ yarn global add code-server
  5. Before starting code-server, we are going to fix an error caused by spdlog, which is a dependency of Visual Studio Code. First, change your working directory to ~/.config/yarn/global/node_modules/code-server/lib/vscode/node_modules/spdlog/:

    $ cd ~/.config/yarn/global/node_modules/code-server/lib/vscode/node_modules/spdlog/
  6. You will need a text editor for the next step. Here Vim is used for this task, but you are free to use whatever text editor you love:

    $ pkg install vim
  7. Open binding.gyp and enter edit mode. You can do this by pressing i once you open the file using Vim:

    $ vim binding.gyp
  8. Add "libraries": [ "-latomic" ] below "target_name": "spdlog",. This helps spdlog compile on Android.

    "targets": [{
            "target_name": "spdlog",
    +       "libraries": [ "-latomic" ],
            "sources": [
                    "src/main.cc",
                    "src/logger.cc"
            ],
  9. Save the file and quit text editor. You can do this by pressing ESC and then wq in Vim:

  10. Recompile spdlog using the following command:

    $ npm install
  11. (Optional) To see if spdlog works, run:

    $ npm test
  12. To fix the file search function of code-server, install ripgrep via pkg and link it to the correct place:

    $ pkg install ripgrep -y
    $ cd ~/.config/yarn/global/node_modules/code-server/lib/vscode/node_modules/vscode-ripgrep/bin
    $ ln -s $(which rg) .
  13. Finally, change the working directory back to home and start code-server with the following command:

    $ cd ~
    $ code-server --auth none --disable-telemetry
  14. Now, you can open your browser and visit code-server at http://localhost:8080.

  15. (Bonus) If you wish to visit this code-server from another device in the same local network, you can expose the HTTP service to all network interfaces by starting code-server with --bind-addr:

    $ code-server --bind-addr 0.0.0.0:8080 --disable-telemetry

    You can find the password under ~/.config/code-server/config.yaml:

    $ cat ~/.config/code-server/config.yaml

    You may also need to enable HTTPS to enable clipboard and others features of Visual Studio Code in browsers. To do this, install openssl-tool and let code-server generate a certificate on startup:

    $ pkg install openssl-tool
    $ code-server --bind-addr 0.0.0.0:8080 --cert --disable-telemetry

    You can get the public IP address of your device using the command below in Termux:

    $ ifconfig
@radaevm
Copy link

radaevm commented Aug 12, 2022

  1. Do you do pkg update after proot-distro login ubuntu?
  2. Try update system packages in Termux pkg update -y
  3. are you using termux version 118?
  4. Look this

@DNAMcKnight
Copy link

@radaevm step 1-3 are done and it still hasn't worked. I'm a noob but I'll try to make 4 work. Thanks, if you can explain in simple steps it would help me greatly if not then that's fine as well.

@sahdev-a1
Copy link

Are these all the commands which I have to give to termux, then VS code will be ready?

@Thunderbolt009
Copy link

How to open local file and live server can anyone help me 😣

@ArifDharmawan
Copy link

Another easy method 😜

termux-setup-storage

pkg install proot-distro (if it doesn't work, change the repository via termux-change-repo)

proot-distro install ubuntu

proot-distro login ubuntu

pkg update

curl -fsSL https://code-server.dev/install.sh | sh

code-server --auth none

Then open your browser minimizing the termux and search on the Google search bar http://127.0.0.1:8080

This method install last version (4.5.1 at the moment)

To install extensions that are not available in the extensions menu (for example, copilot and copilot labs), you need to download the extension in the VSIX format link and install it in the code-server via Extensions: Install from VSIX in command palette

hi, ill try and it works, but i cant paste text from other, what should i must to do with this ?, ill try search in google, but nothing, thanks

@PranitModak
Copy link

in this Ubuntu inside termux npm install does work. Even though I have node 18.9.0 installed and shows the version when I run the command. Any please help.

@Bibiwei-Pere
Copy link

Bibiwei-Pere commented Sep 30, 2022

How to open local file and live server can anyone help me 😣

Exit termux and restart the process...
All extensions will start working

@Loup-Garou911XD
Copy link

Loup-Garou911XD commented Oct 13, 2022

[1/4] Resolving packages...
[2/4] Fetching packages...
error code-server@4.7.1: The engine "node" is incompatible with this module. Expected version "16". Got "18.10.0"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/global for documentation about this command.

Got error,node version 16 is required but i have version 18
how to install version 16 or any other way to fix this

@k2arim99
Copy link

Use nodejs-lts

@Loup-Garou911XD
Copy link

Use nodejs-lts

It gives error

@Bibiwei-Pere
Copy link

Bibiwei-Pere commented Oct 18, 2022

Use nodejs-lts

It gives error

Just try this step below...
It's working perfectly. I'm currently using it.

  1. termux-setup-storage

  2. pkg install proot-distro

  3. proot-distro install ubuntu

  4. proot-distro login ubuntu

  5. pkg update

  6. curl -fsSL https://code-server.dev/install.sh | sh

  7. code-server --auth none

Then open your browser minimizing the termux and search on the Google search bar http://127.0.0.1:8080

@radaevm
Copy link

radaevm commented Oct 18, 2022

make sure you are using the latest version of termux 0.118. In google play the old version is not suitable

@Loup-Garou911XD
Copy link

make sure you are using the latest version of termux 0.118. In google play the old version is not suitable

Yes i am on the latest version installed from fdroid

@Loup-Garou911XD
Copy link

Use nodejs-lts

It gives error

Just try this step below... It's working perfectly. I'm currently using it.

  1. termux-setup-storage
  2. pkg install proot-distro
  3. proot-distro install ubuntu
  4. proot-distro login ubuntu
  5. pkg update
  6. curl -fsSL https://code-server.dev/install.sh | sh
  7. code-server --auth none

Then open your browser minimizing the termux and search on the Google search bar http://127.0.0.1:8080

Ubuntu 22.04 LTS
No standalone releases for armv8l.
Falling back to installation from npm.
Installing latest from npm.

sh: 426: NPM_PATH: not found
Installing with npm.

  • npm install -g code-server --unsafe-perm
    npm ERR! code 1
    npm ERR! path /data/data/com.termux/files/usr/lib/node_modules/code-server npm ERR! command failed
    npm ERR! command sh /tmp/postinstall-d374a316.sh
    npm ERR! Failed to download cloud agent; --link will not work
    npm ERR! Installing Code dependencies... npm ERR! You may not have the required dependencies to build the native modules.
    npm ERR! Please see https://github.com/coder/code-server/blob/main/docs/npm.md
    npm ERR! curl: (22) The requested URL returned error: 404 npm ERR! npm ERR! code 1
    npm ERR! npm ERR! path /data/data/com.termux/files/usr/lib/node_modules/code-server/lib/vscode/node_modules/keytar npm ERR! npm ERR! command failed npm ERR! npm ERR! command sh /tmp/install-7e7e01b5.sh
    npm ERR! npm ERR! > keytar@7.9.0 build npm ERR! npm ERR! > node-gyp rebuild
    npm ERR! npm ERR! gyp info it worked if it ends with ok
    npm ERR! npm ERR! gyp info using node-gyp@9.0.0
    npm ERR! npm ERR! gyp info using node@16.17.1 | android | arm
    npm ERR! npm ERR! gyp info find Python using Python version 3.10.8 found at "/data/data/com.termux/files/usr/bin/python3"
    npm ERR! npm ERR! gyp info spawn /data/data/com.termux/files/usr/bin/python3
    npm ERR! npm ERR! gyp info spawn args [
    npm ERR! npm ERR! gyp info spawn args '/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
    npm ERR! npm ERR! gyp info spawn args 'binding.gyp',
    npm ERR! npm ERR! gyp info spawn args '-f',
    npm ERR! npm ERR! gyp info spawn args 'make',
    npm ERR! npm ERR! gyp info spawn args '-I',
    npm ERR! npm ERR! gyp info spawn args '/data/data/com.termux/files/usr/lib/node_modules/code-server/lib/vscode/node_modules/keytar/build/config.gypi',
    npm ERR! npm ERR! gyp info spawn args '-I',
    npm ERR! npm ERR! gyp info spawn args '/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
    npm ERR! npm ERR! gyp info spawn args '-I',
    npm ERR! npm ERR! gyp info spawn args '/root/.cache/node-gyp/16.17.1/include/node/common.gypi',
    npm ERR! npm ERR! gyp info spawn args '-Dlibrary=shared_library',
    npm ERR! npm ERR! gyp info spawn args '-Dvisibility=default',
    npm ERR! npm ERR! gyp info spawn args '-Dnode_root_dir=/root/.cache/node-gyp/16.17.1',
    npm ERR! npm ERR! gyp info spawn args '-Dnode_gyp_dir=/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/node-gyp',
    npm ERR! npm ERR! gyp info spawn args '-Dnode_lib_file=/root/.cache/node-gyp/16.17.1/<(target_arch)/node.lib',
    npm ERR! npm ERR! gyp info spawn args '-Dmodule_root_dir=/data/data/com.termux/files/usr/lib/node_modules/code-server/lib/vscode/node_modules/keytar',
    npm ERR! npm ERR! gyp info spawn args '-Dnode_engine=v8',
    npm ERR! npm ERR! gyp info spawn args '--depth=.',
    npm ERR! npm ERR! gyp info spawn args '--no-parallel',
    npm ERR! npm ERR! gyp info spawn args '--generator-output',
    npm ERR! npm ERR! gyp info spawn args 'build',
    npm ERR! npm ERR! gyp info spawn args '-Goutput_dir=.'
    npm ERR! npm ERR! gyp info spawn args ]
    npm ERR! npm ERR! Package libsecret-1 was not found in the pkg-config search path.
    npm ERR! npm ERR! Perhaps you should add the directory containing libsecret-1.pc' npm ERR! npm ERR! to the PKG_CONFIG_PATH environment variable npm ERR! npm ERR! No package 'libsecret-1' found npm ERR! npm ERR! gyp: Call to 'pkg-config --cflags libsecret-1' returned exit status 1 while in binding.gyp. while trying to load binding.gyp npm ERR! npm ERR! gyp ERR! configure error npm ERR! npm ERR! gyp ERR! stack Error: gyp` failed with exit code: 1
    npm ERR! npm ERR! gyp ERR! stack at ChildProcess.onCpExit (/data/data/com.termux/files/usr/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:261:16)
    npm ERR! npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:513:28)
    npm ERR! npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
    npm ERR! npm ERR! gyp ERR! System Linux 5.4.0-faked
    npm ERR! npm ERR! 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" "rebuild"
    npm ERR! npm ERR! gyp ERR! cwd /data/data/com.termux/files/usr/lib/node_modules/code-server/lib/vscode/node_modules/keytar
    npm ERR! npm ERR! gyp ERR! node -v v16.17.1
    npm ERR! npm ERR! gyp ERR! node-gyp -v v9.0.0
    npm ERR! npm ERR! gyp ERR! not ok
    npm ERR!
    npm ERR! npm ERR! A complete log of this run can be found in:
    npm ERR! npm ERR! /root/.npm/_logs/2022-10-18T13_32_03_711Z-debug-0.log
    npm ERR! npm ERR! code 1
    npm ERR! npm ERR! path /data/data/com.termux/files/usr/lib/node_modules/code-server/lib/vscode/extensions/node_modules/esbuild
    npm ERR! npm ERR! command failed
    npm ERR! npm ERR! command sh /tmp/postinstall-8f7e646e.sh
    npm ERR! npm ERR! Unsupported platform: android arm LE
    npm ERR!
    npm ERR! npm ERR! A complete log of this run can be found in:
    npm ERR! npm ERR! /root/.npm/_logs/2022-10-18T13_33_48_861Z-debug-0.log

npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2022-10-18T13_30_44_363Z-debug-0.log

I get this error

@anon-coder1
Copy link

@Adventuresofbot While running the code i get this error-
bin/sh : 1: g++: not found

@DivineUX23
Copy link

Screenshot_20221121-083839

Guys please I'm having issues with installing code-server

@DinkyTrady
Copy link

Screenshot_20221121-083839

Guys please I'm having issues with installing code-server

use nodejs-lts

@DinkyTrady
Copy link

@Adventuresofbot While running the code i get this error- bin/sh : 1: g++: not found

maybe you didn't install c-compiler before like clang

@ljlabs
Copy link

ljlabs commented Dec 8, 2022

[1/4] Resolving packages...
[2/4] Fetching packages...
error code-server@4.7.1: The engine "node" is incompatible with this module. Expected version "16". Got "18.10.0"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/global for documentation about this command.

Got error,node version 16 is required but i have version 18 how to install version 16 or any other way to fix this

The last version of nodejs on termux is currently version 16. So simply run
pkg remove nodejs
pkg install nodejs-lts

@PriNova
Copy link

PriNova commented Jan 3, 2023

this is an example in samsung dex mode

image

Thank you for your tip.
I installed copilot and copilot labs.
Copilot is working, but the sidebar of labs shows only the three subtabs empty. I see "explain", "translate" and brushes as expandables but without content.
Do you know, what this can be.
Have termux 0.118 and all lastest versions.

Thank you in advance.

@PillFall
Copy link

PillFall commented Feb 6, 2023

@jaimemrjm
Copy link

jaimemrjm commented Mar 2, 2023

https://coder.com/docs/code-server/latest/termux

Terminal inside vscode from termux package doesn't work for me. There is an open issue.

code-server from proot-distro works fine for me.

@PillFall
Copy link

PillFall commented Mar 2, 2023

https://coder.com/docs/code-server/latest/termux

Terminal inside vscode from termux package doesn't work for me. There is an open issue.

code-server from proot-distro works fine for me.

@jaimemrjm That's a problems that could be easily parsed via, if installed with yarn

sed -i -e 's|switch(process.platform)|switch("linux")|' /data/data/com.termux/files/home/.config/yarn/global/node_modules/code-server/lib/vscode/out/vs/platform/terminal/node/ptyHostMain.js

@jaimemrjm
Copy link

jaimemrjm commented Mar 3, 2023

Terminal inside vscode from termux package doesn't work for me. There is an open issue.

@jaimemrjm That's a problems that could be easily parsed via, if installed with yarn

sed -i -e 's|switch(process.platform)|switch("linux")|' /data/data/com.termux/files/home/.config/yarn/global/node_modules/code-server/lib/vscode/out/vs/platform/terminal/node/ptyHostMain.js

I have installed from termux pkg:

pkg install tur-repo
pkg install code-server

The latest install doc say anything about using yarn to install code-server on Termux:
https://coder.com/docs/code-server/latest/termux#installation

@jaimemrjm
Copy link

Where are the update steps to install code-server from yarn and termux? Note the OP are no longer valid because nodejs package is v19 and nodejs-lte is v18, so I think the code-server will have installation issues because it requires nodejs v16 or v17.

@PillFall
Copy link

PillFall commented Mar 7, 2023

Where are the update steps to install code-server from yarn and termux? Note the OP are no longer valid because nodejs package is v19 and nodejs-lte is v18, so I think the code-server will have installation issues because it requires nodejs v16 or v17.

@jaimemrjm When I installed Code Server on my device with yarn, I use

FORCE_NODE_VERSION=FALSE yarn global add code-server --ignore-engines

Upgrade

FORCE_NODE_VERSION=FALSE yarn global upgrade code-server --ignore-engines

Code Server uses Node v16 because it is the only version VSCode is tested on, but I have seen no issues (beside the terminal) when running on Termux official NodeJS (v19)

But if you want to keep the package from the TUR, there is a nodejs-16 package to keep compatibility with the code-server package

@ScoreUnder
Copy link

Does anyone know a good browser to use for this? One that won't open the print dialog on ctrl+p, and won't close the menus as soon as they open because the keyboard closes.

@PillFall
Copy link

@junmar4

FORCE_NODE_VERSION=FALSE yarn global add code-server --ignore-engines

If you want to check it out, I post a comment before, being more specific on how to install and get the terminal working.

@johnt1989
Copy link

johnt1989 commented Mar 21, 2023

pkg upgrade -y
pkg install nodejs python yarn binutils

v=$(node -v); v=${v#v}; v=${v%%.*};

FORCE_NODE_VERSION="$v" yarn global add code-server@4.6.0 --ignore-engines;

now you have a working code-server on termux not proot

@ankitvishwakarma91
Copy link

Step 1 and 2 run and 3 step not run what I do
Please help anyone

@ankitvishwakarma91
Copy link

Screenshot_2023-04-27-21-49-43-435_com termux
This problem i face

@kingroyal500
Copy link

How can I download VS code for Android?

@PillFall
Copy link

PillFall commented May 1, 2023

@ankitvishwakarma91 You are executing commands that are not valid.

You ask yarn to install code with the flag server. Then you can notice that Node is asking you for libcrypto.so.3. You can install this library with:

apt update && apt upgrade
apt install openssl-tool

@PillFall
Copy link

PillFall commented May 1, 2023

How can I download VS code for Android?

@kingroyal500 The Official VS Code is not available out of the box for Android, neither for Termux. You can install the OSS Version via a package called code-server, taking into account that there will be no support from Microsoft.

@0xR0
Copy link

0xR0 commented May 16, 2023

solution

#!/bin/bash
pkg install proot-distro -y
proot-distro install ubuntu
proot-distro login ubuntu -- bash -c "curl -fsSL https://code-server.dev/install.sh | sh && code-server --auth none"

This script installs the proot-distro package using the command pkg install proot-distro -y. Then, it downloads and installs the Ubuntu distribution using proot-distro install ubuntu. Next, it starts a Ubuntu session using proot-distro login ubuntu. Within the Ubuntu session, it executes the command curl -fsSL https://code-server.dev/install.sh | sh to download and install code-server. Finally, it launches code-server in the mode without authentication using code-server --auth none.

To run the script, you can follow these steps:

1.Open a terminal.
2.Run chmod +x my_script.sh to make the script executable.
3.Run ./my_script.sh to execute the script.

When you run the script, it will perform all the mentioned steps in a single line. This way, the proot-distro and code-server commands will be executed consecutively.
4. Run proot-distro login ubuntu -- bash -c "code-server --auth none"
5. if u want add this line run terminal nano .bashrc
6. alias cc="proot-distro login ubuntu -- bash -c "code-server --auth none"
7. Restart termux
8. Run cc
Screenshot_20230516-183105922
9. go to http://127.0.0.1:8080

Screenshot_20230516-182418738 (1)

@jaimemrjm
Copy link

solution

#!/bin/bash pkg install proot-distro -y proot-distro install ubuntu proot-distro login ubuntu -- bash -c "curl -fsSL https://code-server.dev/install.sh | sh && code-server --auth none"

This script installs the proot-distro package using the command pkg install proot-distro -y. Then, it downloads and installs the Ubuntu distribution using proot-distro install ubuntu. Next, it starts a Ubuntu session using proot-distro login ubuntu. Within the Ubuntu session, it executes the command curl -fsSL https://code-server.dev/install.sh | sh to download and install code-server. Finally, it launches code-server in the mode without authentication using code-server --auth none.

To run the script, you can follow these steps:

1.Open a terminal. 2.Run chmod +x my_script.sh to make the script executable. 3.Run ./my_script.sh to execute the script.

When you run the script, it will perform all the mentioned steps in a single line. This way, the proot-distro and code-server commands will be executed consecutively. 4. Run proot-distro login ubuntu -- bash -c "code-server --auth none" 5. if u want add this line run terminal nano .bashrc 6. alias cc="proot-distro login ubuntu -- bash -c "code-server --auth none" 7. Restart termux 8. Run cc Screenshot_20230516-183105922 9. go to http://127.0.0.1:8080

Screenshot_20230516-182418738 (1)

bad solution: proot is slower than Termux

@lexavey
Copy link

lexavey commented Jul 11, 2023

Terminal inside vscode from termux package doesn't work for me. There is an open issue.

@jaimemrjm That's a problems that could be easily parsed via, if installed with yarn

sed -i -e 's|switch(process.platform)|switch("linux")|' /data/data/com.termux/files/home/.config/yarn/global/node_modules/code-server/lib/vscode/out/vs/platform/terminal/node/ptyHostMain.js

I have installed from termux pkg:

pkg install tur-repo pkg install code-server

The latest install doc say anything about using yarn to install code-server on Termux: https://coder.com/docs/code-server/latest/termux#installation

wow this is amazing, thankyou brother, simple and work solution, just use two lines of code i success install the code-server

code-server: v4.14.1
Code: 1.79.2
Commit: 695af097c7bd098fbf017ce3ac85e09bbc5dda06
Date: 2023-06-27T01:42:16.278Z (2 wks ago)
Browser: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36

terminal also working fine

@corbinlc
Copy link

corbinlc commented Sep 8, 2023

If you want to run actual VS Code, instead of code-server, on Android and skip most of the setup process, you can now use deVStudio https://play.google.com/store/apps/details?id=tech.ula.devstudio&hl=en_US

@jaimemrjm
Copy link

If you want to run actual VS Code, instead of code-server, on Android and skip most of the setup process, you can now use deVStudio https://play.google.com/store/apps/details?id=tech.ula.devstudio&hl=en_US

Too expensive.

@shrinivas2003
Copy link

Bro python is not working showing select interpreter

@vleeuwenmenno
Copy link

I'd recommend updating step 3 to say pkg install -y python nodejs-lts yarn git to make sure it installs Node.js 18 and not 20

@Amrinder-S
Copy link

you really complicating things.

just do apt install code-server
or pkg install code-server

and it would work out just fine.

@PillFall
Copy link

you really complicating things.

just do apt install code-server or pkg install code-server

and it would work out just fine.

@Amrinder-S this only works if you have TUR installed, which is not part of the official Termux repos

@Amrinder-S
Copy link

you really complicating things.
just do apt install code-server or pkg install code-server
and it would work out just fine.

@Amrinder-S this only works if you have TUR installed, which is not part of the official Termux repos

I guess it doesn't hurt to just install code-server with it and then get on with your day. (i ran into the same issue with node version and i got many flashbacks and nightmares from it. i rather not look back into it)

@jaimemrjm
Copy link

you really complicating things.

just do apt install code-server or pkg install code-server

and it would work out just fine.

Since the issue is still open, I suppose pkg install code-server means the Terminal in that vscode is broken.

@carlosdarkoficial
Copy link

Funcionando normalmente show
Só achei complicado as configurações

@AhmdHaris
Copy link

Screenshot_20240306-001348_Termux
error

@PillFall
Copy link

PillFall commented Mar 9, 2024

Screenshot_20240306-001348_Termux error

@AhmdHaris use nodejs-18 (or better code-server directly) from the TUR repo or ignore engine dependencies, early in this gist there is a command on how to install ignoring engine

@esnosy
Copy link

esnosy commented Mar 9, 2024

We should all use something else other than vscode like Nano or Vim,
https://youtu.be/m8C0Cq9Uv9o?si=5qD0JGKFF3IhR-8C
I think vscode is bad sometimes, I used to love it and still, but something about its asynchronousity is flawed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment