Node.js安装错误版本。为什么apt安装无法正常工作?

时间:2019-12-27 16:00:49

标签: node.js linux

我尝试在我的Raspberry Pi上安装Node.js 6。我已经搜索了网络并找到了一个方法,但这对我不起作用。怎么了?

Raspbian GNU / Linux 10(Buster)

curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -

## Installing the NodeSource Node.js 6.x LTS Boron repo...

## Populating apt-get cache...

+ apt-get update
OK:1 http://raspbian.raspberrypi.org/raspbian buster InRelease
OK:2 http://archive.raspberrypi.org/debian buster InRelease
OK:3 https://deb.nodesource.com/node_6.x buster InRelease
Paketlisten werden gelesen... Fertig

## Confirming "buster" is supported...

+ curl -sLf -o /dev/null 'https://deb.nodesource.com/node_6.x/dists/buster/Release'

## Adding the NodeSource signing key to your keyring...

+ curl -s https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -
OK

## Creating apt sources list file for the NodeSource Node.js 6.x LTS Boron repo...

+ echo 'deb https://deb.nodesource.com/node_6.x buster main' > /etc/apt/sources.list.d/nodesource.list
+ echo 'deb-src https://deb.nodesource.com/node_6.x buster main' >> /etc/apt/sources.list.d/nodesource.list

## Running `apt-get update` for you...

+ apt-get update
OK:1 http://raspbian.raspberrypi.org/raspbian buster InRelease
OK:2 http://archive.raspberrypi.org/debian buster InRelease
OK:3 https://deb.nodesource.com/node_6.x buster InRelease
Paketlisten werden gelesen... Fertig

## Run `sudo apt-get install -y nodejs` to install Node.js 6.x LTS Boron and npm
## You may also need development tools to build native addons:
     sudo apt-get install gcc g++ make
## To install the Yarn package manager, run:
     curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
     echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
     sudo apt-get update && sudo apt-get install yarn
root@Raspi:/home/pi# apt-get install --yes nodejs

Paketlisten werden gelesen... Fertig
Abhängigkeitsbaum wird aufgebaut.
Statusinformationen werden eingelesen.... Fertig
Die folgenden Pakete wurden automatisch installiert und werden nicht mehr benötigt:
  gyp libjs-inherits libjs-is-typedarray libnode-dev libssl-dev libuv1-dev python-pkg-resources
Verwenden Sie »apt autoremove«, um sie zu entfernen.
Vorgeschlagene Pakete:
  npm
Die folgenden NEUEN Pakete werden installiert:
  nodejs
0 aktualisiert, 1 neu installiert, 0 zu entfernen und 2 nicht aktualisiert.
Es müssen noch 0 B von 86,5 kB an Archiven heruntergeladen werden.
Nach dieser Operation werden 153 kB Plattenplatz zusätzlich benutzt.
Vormals nicht ausgewähltes Paket nodejs wird gewählt.
(Lese Datenbank ... 51780 Dateien und Verzeichnisse sind derzeit installiert.)
Vorbereitung zum Entpacken von .../nodejs_10.15.2~dfsg-2+rpi1_armhf.deb ...
Entpacken von nodejs (10.15.2~dfsg-2+rpi1) ...
nodejs (10.15.2~dfsg-2+rpi1) wird eingerichtet ...
update-alternatives: /usr/bin/nodejs wird verwendet, um /usr/bin/js (js) im automatischen Modus bereitzustellen
Trigger für man-db (2.8.5-2) werden verarbeitet ... 

我已经尝试使用sudo并也以root身份使用。

为什么仍要安装Node.js 10?

知道要做什么吗?

1 个答案:

答案 0 :(得分:0)

从节点站点获取您的nodejs tarball,例如v6.11.3起的node-v6.11.3-linux-x64.tar.gz

public void RetrieveAndInsert (String downloadUri, Uri localUri) {
    new RetrieveTask(localUri).execute(downloadUri);
}
class RetrieveTask extends AsyncTask<String, Void, Void> {

    String downloadUri;
    Uri localUri;

    RetrieveTask(Uri localUri) {
        this.localUri = localUri;
    }
    @Override
    protected Void doInBackground(final String... downloadUri) {

        this.downloadUri = downloadUri[0];
        InputStream inp = null;
        OutputStream output = null;
        try{
            URL url = new URL(this.downloadUri);
            URLConnection urlCon = url.openConnection();
            HttpURLConnection httpCon = (HttpURLConnection) urlCon;
            httpCon.connect();
            output = cr.openOutputStream(localUri);
            int lengthOfFile = httpCon.getContentLength();
            inp = new BufferedInputStream(url.openStream(), 8192);// httpCon.getInputStream();

            byte[] buffer = new byte[1024];
            int bytesRead;
            long total = 0;
            while ((bytesRead = inp.read(buffer)) != -1) {
                total += bytesRead;
                output.write(buffer, 0, bytesRead);
            }
            downloadedFiles[0]++;
        } catch (MalformedURLException e) {
            e.printStackTrace();
            cr.delete(localUri, null, null);
        } catch (IOException e) {
            e.printStackTrace();
            cr.delete(localUri, null, null);
        } finally{
            try {
                inp.close();
                output.flush();
                output.close();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (Exception e){
                e.printStackTrace();
            }

            ContentValues values = new ContentValues();
            values.put(MediaStore.MediaColumns.IS_PENDING, 0);
            cr.update(localUri, values, null, null);
        }

        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        //
    }
}

将提供的存档文件解压缩到/ opt / nodejs

wget nodejs.org/dist/v8.12.0/node-v8.12.0-linux-armv7l.tar.gz

创建指向当前节点版本的链接

mkdir -p /opt/nodejs
tar -xvzf node-v8.12.0-linux-armv7l.tar.gz -C /opt/nodejs/

创建指向当前节点二进制文件的链接

cd /opt/nodejs
mv node-v8.12.0-linux-armv7l 8.12.0
ln -s 8.12.0 current

验证节点版本

ln -s /opt/nodejs/current/bin/node /bin/node

v8.12.0